单链表的简单写法
#include<stdio.h>
#include<stdlib.h>
typedef int Element;
typedef struct Node
{
Element data;
Node *next;
};
Node* Create(int n)
{
Node *L;
L = (Node *)malloc(sizeof(Node));
L->next = NULL;
Node *r;
r = L;
while(n--)
{
Node *p;
p = (Node *)malloc(sizeof(Node));
p->data = n;
r->next= p;
r = p;
}
r->next = NULL;
return L;
}
void show(Node *L)
{
Node *p = L->next;
while(p->next != NULL)
{
printf("%d ", p->data);
p= p->next;
}
}
int main()
{
int n=10;
Node *L;
L = (Node *)malloc(sizeof(Node));
L = Create(n);
show(L);
printf("ok");
}