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

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

求問(wèn)為什么我的程序會(huì)奔潰掉

求問(wèn)為什么我的程序會(huì)奔潰掉

#include<iostream>using namespace std;class MyStack {public: MyStack(int Size); ~MyStack(); bool stackEmpty(); bool stackFull(); void clearStack(); int stackLength(); //char push(char elem); bool push(char elem); bool pop(char &elem); void stackTravel();private: int size; int top; char *pStack;};?MyStack::MyStack(int Size){? size=0; top=0; size = Size; pStack = new char(Size); cout<<"申請(qǐng)"<<size<<"個(gè)內(nèi)存的空間!"<<endl;}MyStack::~MyStack(){ delete []pStack; pStack=NULL;cout<<"delete"<<endl;}bool MyStack::stackEmpty(){ if (top==0) return true; else return false;}bool MyStack::stackFull(){ if(size==top) return true; else return false;}void MyStack::clearStack(){ top = 0;//覆蓋}int MyStack::stackLength(){ return ?top;}bool MyStack::push(char elem){ if(stackFull()){ return false; } pStack[top]=elem; top++; return true;}bool MyStack::pop(char &elem){ ? ? if(!stackEmpty())? ? {? ? ? ? top--;? ? ? ? elem=pStack[top];? ? ? ? ?? ? ? ? return true;? ? }? ? else? ? {? ? ? ? return false;? ? } }void MyStack::stackTravel(){ for (int i = 0;i < top;i++) { cout << pStack[i]; } cout << endl;}int main() { MyStack pStack(5); char elem; char num[5]={'1','2','3','4','5'}; for(int i=0;i<5;i++){ pStack.push(num[i]); } //pStack.push('p'); //pStack.push('p'); pStack.pop(elem); if (pStack.stackEmpty()) { cout << "The stack is empty"<<endl; } if (pStack.stackFull()) { cout << "The stack is full" << endl; } cout << "The stack's length:" << pStack.stackLength() << endl; /*pStack.push('a'); pStack.push('p'); pStack.push('p'); pStack.push('l');*/ //pStack.push('e'); //pStack.stackTravel(); /*pStack.pop(elem); cout << elem << endl; pStack.clearStack();*/ //cout << "The stack's length:" << pStack.stackLength() << endl; return 0;}
查看完整描述

2 回答

?
下雨何

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

sorry,不懂c

不過(guò)大體上了解一點(diǎn)點(diǎn),要注意變量的聲明和銷毀,另外注意變量類型

c不比php,它是強(qiáng)數(shù)據(jù)類型,不能簡(jiǎn)單隨意的轉(zhuǎn)換數(shù)據(jù)類型

c不比java,它對(duì)內(nèi)存的控制比較嚴(yán)格,不像java,都叫給虛擬機(jī),不用管這些,同時(shí)java也不用考慮指針

建議多了解一點(diǎn) 指針,數(shù)據(jù)在內(nèi)存的存放等等

查看完整回答
反對(duì) 回復(fù) 2016-09-13
?
onemoo

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

在構(gòu)造函數(shù)中,你想申請(qǐng)一塊連續(xù)size個(gè)char內(nèi)存,是不是?

pStack = new char(Size);

不過(guò)上面這代碼寫錯(cuò)了,申請(qǐng)一塊連續(xù)內(nèi)存需要在類型后用中括號(hào) [ ]。 你寫成了小括號(hào),這樣只是申請(qǐng)了一個(gè)char內(nèi)存,其初值為size而已。

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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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