第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

C++數(shù)據(jù)結(jié)構(gòu)(鏈棧) 檢查了好多遍,不明白錯(cuò)在哪

C++數(shù)據(jù)結(jié)構(gòu)(鏈棧) 檢查了好多遍,不明白錯(cuò)在哪

C++
愛(ài)3 2015-10-24 19:03:43
頭文件LinkStack.h #ifndef?LINKSTACK_H //如果沒(méi)有定義該?頭文件,就執(zhí)行以下的(define),否則就直接endif(避免二次調(diào)用 #define?LINKSTACK_H template<class?DataType>????????//模板類(lèi) class?LinkStack?????????????????//鏈棧定義 { public: LinkStack();?????????????????????????????//構(gòu)造函數(shù) ~LinkStack();???????????????//析構(gòu)函數(shù) void?Push(DataType?x);???????????????????//入棧,增加 DataType?Pop();?????????????//出棧,刪除 DataType?GetTop();??????????????????????//取棧頂元素,不刪除 int?Empty();????????????????//判空 private: Node<DataType>?*top?????????//棧頂指針 }; #endif 源文件LinkStack.cpp #include<iostream> using?namespace?std; #include?"LinkStack.h"?????????????????????????????//包含頭文件 template<class?DataType> LinkStack<DataType>::LinkStack()??????????????????// { top=NULL;?????????????????????????????????????//棧頂指針初始化為空 } template<class?DataType> LinkStack<DataType>::~LinkStack()?????????????????//析構(gòu)函數(shù) { } template<class?DataType> void?LinkStack<DataType>::Push(DataType?x) { s=new?Node;???s->data=x; ?//申請(qǐng)一個(gè)數(shù)據(jù)域?yàn)閤的節(jié)點(diǎn)s,next指向 s->next=top;??top=s; ?//將節(jié)點(diǎn)s插在棧頂 } template<class?DataType> DataType?LinkStack<DataType>::Pop() ????? { if(top==NULL)?throw?"下溢";?????????????????// x=top->data;?p=top; top=top->next; delete?p; return?x; } template<class?DataType> DataType?GetTop() { if(top!=?NULL)??????????????????????????????//不刪除 return?top->data; } template<class?DataType> int?Empty() { top==NULL???return?1:return?0; } 主函數(shù)文件LinkStackMain.cpp #include<iostream> using?namespace?std; #include"LinkStack.cpp" void?main() { LinkStack<int>?L;???????????????????????????//實(shí)例化類(lèi)對(duì)象 if(L.Empty()==1) //判空 cout<<"棧為空"<<endl; else?cout<<"棧為非空"<<endl; L.Push(2);?????????????????????????????????//依次入棧 L.Push(3); cout<<"棧頂元素為:"<<L.GetTop()<<endl;????//取棧頂元素 //cout<<"出棧:"<<L.Pop()<<endl;??? cout<<"出棧:"<<endl; L.Pop(); cout<<"棧頂元素為:"<<L.GetTop()<<endl;????//出棧一次,棧頂元素改變 system("pause"); }
查看完整描述

1 回答

?
onemoo

TA貢獻(xiàn)883條經(jīng)驗(yàn) 獲得超454個(gè)贊

出了錯(cuò)誤先看報(bào)的是什么錯(cuò)! 說(shuō)說(shuō)報(bào)錯(cuò)是什么?

目測(cè)就有幾個(gè)問(wèn)題:

  • LinkStackMain.cpp中你include了LinkStack.cpp文件,這直接就會(huì)引起重定義錯(cuò)誤。永遠(yuǎn)不要include包含實(shí)現(xiàn)的.cpp文件!

  • 我沒(méi)看到Node類(lèi)型的定義

查看完整回答
反對(duì) 回復(fù) 2015-10-25
  • 1 回答
  • 0 關(guān)注
  • 1643 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)