#include #include #define N 8
//这个链表有8个元素typedef struct list{int data; struct list *next;} SLIST;
//定义链表的结构体SLIST *creatlist(int *a)
//建立链表{SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; idata=a; p->next=q; p=q; } p->next=0; return h;}void outlist(SLIST *h)
//输出链表{SLIST *p; p=h->next; if (p==NULL) printf("\nThe list is NULL!\n"); else {printf("\nHead");
do {printf("->%d",p->data); p=p->next;} while(p!=NULL);
printf("->End\n");}}void main(){SLIST *head; int a[N];
int i;
for(i=0;idata));}else{ q->data=rand();}q->next=L->next;L->next=q; }}void LinkListDump(LinkList L){ Node *p=L->next; while(p) {printf("%d\t",p->data);p=p->next; } printf("\n");}int main(){ int len; printf("Please enter the number of the elements:\n"); scanf("%d",&len); int flag=0;//if flag==1,you will input the elements,else by random; LinkList L; L=(Node*)malloc(sizeof(Node));//with the head node; L->next=NULL; CreateLinkList(L,flag,len); LinkListDump(L); return 0;}你看这样行不行? |