69,369
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Node)
//int n;
struct Node
{
int x;
struct Node *next;
};
struct Node *CreateLList();
struct Node *SortLList(struct Node *head);
void PrintLList(struct Node *head);
//void main()
int main()
{
struct Node *h1,*h2;
h1=CreateLList();
PrintLList(h1);
h2=CreateLList();
PrintLList(h2);
}
void PrintLList(struct Node *head)
{
struct Node *p;
p = head;
printf("the new records are:\n");
//if(head!=NULL)
if(!head)
return;
do {
printf("%d ", p->x);
p = p->next;
//} while(p->next!=NULL);
} while(p!=NULL);
putchar(10);
}
struct Node *CreateLList()
{
struct Node *head,*p;
int n=0;
head = p = (struct Node*)malloc(LEN);
if (!p)
exit(0);
scanf("%d", &p->x);
//head=NULL;
while(p->x != 0)
{
++n;
if(n==1)
{
head = p;
head->next = NULL;
}
else
{
p->next = head->next;
head->next = p;
}
p = (struct Node*)malloc(LEN);
if (!p)
exit(0);
scanf("%d", &p->x);
}
free(p);
return head;
}