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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

大家可以幫忙解決這個問題么,跟著老師打的可是輸出亂碼了

大家可以幫忙解決這個問題么,跟著老師打的可是輸出亂碼了

#include<stdlib.h> #include<iostream> #include<string> using?namespace?std; class?Node { public: int?data;//數(shù)據(jù)域 Node?*next;//指向下一個結(jié)點的指針域 void?printNode();//打印數(shù)據(jù)域? }?; class?List? { public: List()?;?//構(gòu)造函數(shù),創(chuàng)建線性表? ~List();//析構(gòu)函數(shù),釋放線性表 void?ClearList();//清空線性表? bool?ListEmpty();//判斷線性表是否為空? int?ListLength();//獲取當(dāng)前線性表的長度? bool?GetElem(int?i,Node?*pNode);?//獲取指定元素的值?? ????int?LocateElem(Node?*pNode);?//找與給定結(jié)點相同數(shù)據(jù)域?的結(jié)點的位置? bool?PriorElem(Node?*pCurrentNode,Node?*pPreNode);//獲取指定元素的前驅(qū)? bool?NextElem(Node?*pCurrentNode,Node?*pNextNode);//獲取指定元素的后繼? ????void?ListTraverse();//遍歷線性表? bool?ListInsert(int?i,Node?*pNode); //在第i個結(jié)點插入元素? bool?ListDelete(int?i,Node?*pNode);//在刪除第i個位置的元素? bool?ListInsertHead(Node?*pNode);//從頭結(jié)點后插入 bool?ListInsertTail(Node?*pNode);//從尾結(jié)后插入 ? private: Node?*m_pList;//指向存儲線性表的內(nèi)存? int?m_iLength;//線性表的長度? //對于鏈表不需要size,因為其內(nèi)存空間可以臨時申請? ?}?; class?Person { public: string?name; string?phone; Person?&operator=(Person?&person); }; ?void?Node::printNode() { cout<<data<<endl; ?}? ? ?List::List() { m_pList=new?Node;//從堆中申請內(nèi)存? //m_pList->data=0;//第一個結(jié)點數(shù)據(jù)域賦值零? m_pList->next=NULL;?//指針域空 m_iLength=0;? } List::~List?()//清空所有結(jié)點? { ClearList(); delete?m_pList; m_pList=NULL; } void?List::ClearList()//清空除了頭結(jié)點外所有結(jié)點? { Node?*currentNode=m_pList->next; while(currentNode!=NULL) { Node?*temp=currentNode->next; delete?currentNode; currentNode=temp;? } m_pList->next=NULL; } bool?List::ListEmpty() { if(m_iLength==0) { return?true; } else { return?false; } //return?m_iLength==0?true:false; } int?List::ListLength() { return?m_iLength; } bool?List::GetElem(int?i,Node?*pNode) { if(i<0||i>=m_iLength) { return?false; } Node?*currentNode=m_pList;//臨時變量找到結(jié)點 Node?*currentNodeBefore=NULL;? ????for(int?k=0;k<=i;k++) ????{ ???? currentNodeBefore=currentNode; ???? currentNode=currentNode->next; } pNode->data=currentNode->data; return?true; } int?List::LocateElem(Node?*pNode)//找與pNode數(shù)據(jù)域相同的結(jié)點? { Node?*currentNode=m_pList; while(currentNode->next!=NULL) { int?count=0; currentNode=currentNode->next; if(currentNode->data==pNode->data)//數(shù)據(jù)域的對比? { return?count; } count++; } return?-1; } //注意頭結(jié)點數(shù)據(jù)域沒意義,不能算頭結(jié)點 ? bool?List::PriorElem(Node?*pCurrentNode,Node?*pPreNode) { Node?*currentNode=m_pList; Node?*tempNode=NULL; while(currentNode->next!=NULL) { tempNode=currentNode; currentNode=currentNode->next; if(currentNode->data==pCurrentNode->data)//數(shù)據(jù)域的對比? { if(tempNode==m_pList)//當(dāng)前結(jié)點是否是頭結(jié)點? { return?false;? } pPreNode->data=tempNode->data; return?true; } } return?false; } bool?List::NextElem(Node?*pCurrentNode,Node?*pNextNode) { Node?*currentNode=m_pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; if(currentNode->data==pCurrentNode->data)//數(shù)據(jù)域的對比? { if(currentNode->next==NULL)//當(dāng)前結(jié)點是否是頭結(jié)點? { return?false;? } pNextNode->data=currentNode->data; return?true; } } return?false; } void?List::ListTraverse() { ???Node?*currentNode=m_pList; ???while(currentNode->next!=NULL) ???{ ??? currentNode=currentNode->next; ??? currentNode->printNode(); ???} } bool?List::ListInsert(int?i,Node?*pNode) { if(i<0||i>m_iLength) { return?false; } Node?*currentNode=m_pList;? for(int?k=0;k<i;k++) { ???currentNode=currentNode->next; } Node?*newNode=new?Node; if(newNode==NULL) { return?false;//內(nèi)存申請失敗?? } newNode->data=pNode->data; newNode->next=currentNode->next; currentNode->next=new?Node;? return?true;? } bool?List::ListDelete(int?i,Node?*pNode) { ????if(i<0||i>=m_iLength) { return?false; } ????Node?*currentNode=m_pList;//臨時變量找到結(jié)點 Node?*currentNodeBefore=NULL;? ????for(int?k=0;k<=i;k++) ????{ ???? currentNodeBefore=currentNode; ???? currentNode=currentNode->next; } currentNodeBefore->next=currentNode->next; pNode->data=currentNode->data; delete?currentNode; m_iLength--; return?true; }? bool?List::ListInsertHead(Node?*pNode) { Node?*temp=m_pList->next; Node?*newNode=new?Node;//從堆中申請內(nèi)存,不能從棧中申請內(nèi)存? if(newNode==NULL) { return?false;//內(nèi)存申請失敗? } newNode->data=pNode->data;? m_pList->next=newNode; newNode->next=temp;? return?true; } bool?List::ListInsertTail(Node?*pNode) { Node?*currentNode=m_pList; while(currentNode->next!=NULL) { currentNode=currentNode->next; } Node?*newNode=new?Node;? if(newNode==NULL) { return?false;//內(nèi)存申請失敗?? } newNode->data=pNode->data; newNode->next=NULL; currentNode->next=new?Node; return?true; } int?main(void)? { ????Node?node1; node1.data=3; Node?node2; node2.data=4; Node?node3; node3.data=5; Node?node4; node4.data=6; Node?node5; node5.data=7; List?*pList=new?List(); ????pList->ListInsertHead(&node1); ????pList->ListInsertHead(&node2); pList->ListInsertHead(&node3); pList->ListInsertHead(&node4); ????/*pList->ListInsertTail(&node1); ????pList->ListInsertTail(&node2); pList->ListInsertTail(&node3); pList->ListInsertTail(&node4);*/ pList->ListInsert(0,&node5); pList->ListTraverse(); delete?pList; pList=NULL; system("pause"); return?0; }
查看完整描述

2 回答

已采納
?
JustWannaHugU

TA貢獻452條經(jīng)驗 獲得超796個贊

最好的辦法就是自己在敲一遍!

查看完整回答
反對 回復(fù) 2016-09-20
?
Smile_Smile

TA貢獻6條經(jīng)驗 獲得超1個贊

調(diào)試看看錯在哪

查看完整回答
反對 回復(fù) 2016-09-22
  • 2 回答
  • 0 關(guān)注
  • 1768 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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