mrs_empress
2017-03-18 18:01:38
#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'|
3 回答
已采納

朕日理萬機
TA貢獻(xiàn)27條經(jīng)驗 獲得超28個贊
別的,部分沒看,你目前的問題,LinkList(第10行),不是一個類型名,而是一個變量名,是一個指針類型指向了一個Node實例。而你在后面的代碼中把它當(dāng)成了一個類型名用。

SupperMary
TA貢獻(xiàn)5條經(jīng)驗 獲得超0個贊
編譯報錯在12行,手動去掉"LinkList?&L"之后。
報錯信息“error:?variable?or?field?'CreateList'?declared?void|”沒有了,應(yīng)該是鏈表格式?jīng)]寫對(我還沒有學(xué)過鏈表,不知道具體情況)
報錯信息“error:?'L'?was?not?declared?in?this?scope|”也沒有了
把“void?CreateList(LinkList?&L,int?n);”改成“void?CreateList(int?n,LinkList?&L);”之后,報錯信息”error:?expected?primary-expression?before?'int'|“也沒有了,說明問題還是出在“LinkList &L”上,很有可能是函數(shù)格式不對。
- 3 回答
- 0 關(guān)注
- 2480 瀏覽
添加回答
舉報
0/150
提交
取消