#include<stdio.h>
#include<stdlib.h>
typedef int elemtype;
typedef struct LNode
{
elemtype data;
struct LNode* next;
}LNode, * Listlink;
LNode* Creatlist1(LNode* L, int n)
{
LNode* q;
L->next = L;
int i = 0;
int x;
printf("请输入你要插入的数:\n");
while (i < n)
{
q = (LNode*)malloc(sizeof(LNode));
scanf_s("%d", &x);
q->data = x;
q->next = L->next;
L->next = q;
i++;
}
return L;
}
LNode* Creatlist2(LNode* L, int n)
{
LNode* q,*r=L;
L->next = L;
int i = 0;
int x;
printf("请输入你要插入的数:\n");
while (i < n)
{
q= (LNode*)malloc(sizeof(LNode));
scanf_s("%d", &x);
q->data = x;
q->next=r->next;
r->next = q;
r = q;
i++;
}
return L;
}
void Printflist(Listlink L,int n)
{
int i = 0;
L = L->next;
while (i<n)
{
printf("%4d", L->data);
L = L->next;
i++;
}
printf("\n");
}
int main()
{
LNode* L;
L = (LNode*)malloc(sizeof(LNode));
Creatlist2(L, 4);
Printflist(L,4);
}
C语言数据结构循环单链表
最新推荐文章于 2024-05-12 17:27:24 发布