#include <stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct LNode{
int data;
struct LNode *next;
}Node,*LinkList;
//创建循环链表
int createLinkList(LinkList &L,int length){
LinkList head,p;
L = (LinkList)malloc(sizeof(Node));
if(!L){
printf("malloc action error");
return 0;
}
L->next = L;
head = L;
int j=0;
for(;j<length;j++){
p = (LinkList)malloc(sizeof(Node));
if(!p){
printf("malloc action error");
return 0;
}
scanf("%d",&p->data);
p->next = head->next;
head->next = p;
head = p;
}
return 1;
}
int printfLinkList(LinkList L){
LinkList head;
head = L->next;
while(head!=L){
printf("%d ",head->data);
head = head->next;
}
return 1;
}
int main()
{
LinkList L;
int length;
printf("please input the LinkList length\n");
scanf("%d",&length);
createLinkList(L,length);
printf("printf the LinkList \n");
printfLinkList(L);
}
回顾数据结构(2):单循环链表
最新推荐文章于 2024-09-18 12:56:12 发布