两天改n遍,请哥哥姐姐们再给指下错误啊[链表创建,输出,删除]
程序代码:
#include<stdio.h> #include<stdlib.h> #define INFEASIBLE -2; #define OK 0; struct node{ int data; struct node *next; }; typedef struct node linklist; int creast(linklist *h,int n); int del(linklist *h); int scan(linklist *h); int main(){ int n,i; linklist *h; printf("Please input the n:"); scanf("%d",&n); h=(linklist*)malloc(sizeof(struct node)); creast(h,n); for(i=0;i<n;i++){ scan(h); del(h); } return 0; } int creast(linklist *h,int n){ printf("Please input the data:"); int i; linklist *p; h=(linklist*)malloc(sizeof(struct node)); if(!h) return INFEASIBLE; h->next=NULL; for(i=n;i>0;i--){ p=(linklist*)malloc(sizeof(struct node)); if(!p) return INFEASIBLE; scanf("%d",&p->data); p->next=h->next; h->next=p; } return OK; } int scan(linklist *h){ linklist *m; if(h=NULL) printf("Empty List!\n"); m=(linklist*)malloc(sizeof(struct node)); m=h; while(m){ printf("%d\t",m->next->data); m=m->next; } return OK; } int del(linklist *h){ linklist *q; q=(linklist*)malloc(sizeof(struct node)); q=h->next; h->next=q->next; free(q); return OK; }