单向循环链表的尾插法实现

`#include<stdio.h>

include<stdlib.h>

typedef struct slik{
int data;
struct slik* next;
}sli;

void createsli(sli** head, int a[],int size){

for(int i=0;i<size;i++){
    sli* s=(sli*)malloc(sizeof(sli));
    s->data=a[i];
    s->next=NULL;
     if (*head == NULL) {
    *head = s;
} else {
    // Find the last node
   
    // Append the new node at the end
    s->next = (*head);
   
    (*head)=s;
}
 

}

sli* last = *head;
while (last->next != NULL) {
last = last->next;
}
last->next = *head;

}
// void ppeet(sli **head){
// while((head)->next!=(head)){
// printf("%d ",(*head)->next);
// head=(head)->next;
// }

// }
void ppeet(sli *head) {
sli current = head;
do {
printf("%d ", current->data);
current = current->next;
} while (current != head);
}
int main(){
sli
head= NULL;
int a[]={4,5,6,4,6,4,6,3,6,3};
createsli(&head,a,10);
ppeet(head);

}`````````````````````````

posted on   jjjkkklll  阅读(12)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示