建立一个单向链表,并依次显示表中各元素

来源:百度知道 编辑:UC知道 时间:2024/06/21 20:06:10
建立一个单向链表,并依次显示表中各元素。
#include <iostream.h>
#include <string.h>
struct node
{ char str[20]; node* next;};
node* head=NULL;
node* create()
{ node* ps,* pend;
ps=____________; cin>>ps->str ;
while((strcmp(_________,"end")))
{ if(head==NULL) head=ps;
else pend->next=ps;
_________;ps=new node;cin>>ps->str ;
}
________________ delete ps; return (head);
}
void showlist(node* head)
{ while(head) {cout<<head->str<<endl;
____________
}
}
void main()
{showlist(create()); }

填空题

#include <iostream.h>
#include <string.h>
struct node
{ char str[20]; node* next;};
node* head=NULL;
node* create()
{ node* ps,* pend;
ps=____________; cin>>ps->str ; //new node
while((strcmp(_________,"end"))) //ps -> str
{ if(head==NULL) head=ps;
else pend->next=ps;
_________;ps=new node;cin>>ps->str ; //pend = ps
}
________________ delete ps; return (head); //if (ps)
}
void showlist(node* head)
{ while(head) {cout<<head->str<<endl;
____________ //head = head -> next;
}
}
void main()
{showlist(create()); }
最后就是:
///////////////////////////
#include <iostream.h>
#include <string.h>
struct node
{ char str[20]; node* next;};
node* head=NULL;
node* create()
{ node* ps,* pend;
ps=new node
; cin>>ps->str ; //
while((s