您的位置:首页 > 理论基础 > 数据结构算法

回顾数据结构(2):单循环链表

2016-11-05 13:35 253 查看
#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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息