为什么没有任何的内容输出? #include<iostream.h> struct NODE { int data; NODE *next; };
NODE *head=NULL; NODE *p; int data[6]={25,41,17,98,5,67}; void OutputList(NODE *head); void InsertList(NODE *head,int aData,int bData); void DeleteList(NODE *head,int aData);
void OutputList(NODE *head) { NODE *current=head; while(current!=NULL) { cout<<current->data<<" "; current=current->next; }
cout<<endl; }
void InsertList(NODE *head,int aData,int bData) { NODE *p,*q,*s; s=(NODE *)new(NODE); s->data=bData; p=head; if(p==NULL) { head=s; s->next=NULL; } else if(p->data==aData) { s->next=p; head=s; } else { while(p->data!=aData&&p->next!=NULL) { q=p; p=p->next; } if(p->data==aData) { q->next=s; s->next=p; } else { p->next=s; s->next=NULL; } }
}
void DeleteList(NODE *head,int aData) { NODE *p,*q; p=head; if(p==NULL) return; if(p->data==aData) { head=p->next; delete p; } else { while(p->data!=aData&&p->next!=NULL) { q=p; p=p->next; } if(p->data==aData) { q->next=p->next; delete p; } } }
void main() { for(int i=0;i<6;i++) InsertList(head,data[0],data[i]); OutputList(head); DeleteList(head,98); DeleteList(head,41); OutputList(head); }