#include?<iostream>
#include?<cstdio>
using?namespace?std;
typedef?int?ElemType;
typedef?int?Status;
const?int?n=5;
struct?Node{
????ElemType?data;
????struct?Node?*next;
}Node,*LinkList;
void?print_title();
void?CreateList(LinkList?&L,int?n);
Status?ListDelete_first(LinkList?&L);
Status?ListTraverse(LinkList?&L);
int?main(){
????int?x;
????ElemType?e;
????LinkList?L;
????CreateList(L,n);
????print_title();
????scanf("%d",&x);
????switch(x){
????????????case?1:ListDelete_first(L);break;
????????????case?2:ListTraverse(L);break;
????????????default:;
????}
????return?0;
}
void?print_title(){
????cout<<"Delete?a?number?in?the?first,input?1;"<<endl;
????cout<<"See?all?numbers,input?2;"<<endl;
????cout<<"Quit,input?any?other?characters."<<endl;
}
void?CreateList(LinkList?&L,int?n){
????LinkList?p;
????L=(LinkList)malloc(sizeof(Node));
????L->next=NULL;
????for(i=n;i>0;--i){
????????p=(LinkList)malloc(sizeof(Node));
????????cin>>p->data;
????????p->next=L->next;
????????L->next=p;
????}
}
Status??ListDelete_first(LinkList?&L){
????LinkList?p;
????p=L->next;
????if(!p)return?false;
????p=p->next;
????L->next=L->next->next;
????free(p);
????p=NULL;
????return?true;
}
Status??ListTraverse(LinkList?&L){
????LinkList?p;
????p=L->next;
????if(!p){
????????cout<<"empty?list!"<<endl;
????????return?false;
????}
????while(p->next){
????????p=p->next;
????????cout<<p->data<<"\t";
????}
????cout<<endl;
????return?true;
}
//error:?variable?or?field?'CreateList'?declared?void|
//error:?'L'?was?not?declared?in?this?scope|
//error:?expected?primary-expression?before?'int'|
c++的引用不知道為什么會報錯?求指教!
mrs_empress
2017-03-18 18:01:38