亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

請問這是什么意思吶?沒調用push()的時候是沒問題的?

請問這是什么意思吶?沒調用push()的時候是沒問題的?

C++
慕斯5158549 2017-12-23 00:56:16
#include"Mystack.h"#include<iostream>#include<string>using namespace std;Mystack::Mystack(int size){ m_isize=size; m_pbuffer=new char[m_isize]; m_itop=0;}Mystack::~Mystack(){ delete []m_pbuffer;}bool Mystack::stackempty(){ if (0==m_itop) { cout<<"???<<endl; return true; } return false;}bool Mystack::stackfull(){ if (m_itop==m_isize) { cout<<"棧滿"<<endl; return true; } return false;}void Mystack::clearstack(){ m_itop=0;}int Mystack::stacklenght(){ return m_itop;}bool Mystack:: push(char &elem){ if (stackfull()) { cout<<"zhan man le !"<<endl; return false; } m_pbuffer[m_itop]=elem; m_itop++; return true;}// char Mystack::pop()// {// if (stackempty())// {// throw 1;// }// else// {// m_itop--;// return m_pbuffer[m_itop];// }// }bool Mystack:: pop(char&elem){ if (stackempty()) { return false; } m_itop--; elem=m_pbuffer[m_itop]; return true;}void Mystack::stacktraverse(bool isfrombuttom/*visit()*/){ if (isfrombuttom) { for (int i=0;i<m_itop;i++) cout<<m_pbuffer[i]<<","; } else { for (int i=m_itop-1;i>=0;i--) cout<<m_pbuffer[i]<<","; } }#ifndef MYSTACK_H#define MYSTACK_Hclass Mystack{public: Mystack(int size); ~Mystack(); bool stackempty(); bool stackfull(); void clearstack(); int stacklenght(); bool push(char &elem); bool pop(char&elem); void stacktraverse(bool isfrombuttom);private: char*m_pbuffer; int m_isize; int m_itop;};#endif#include "Mystack.h"#include <iostream>using namespace std;int main(){ Mystack *p=new Mystack(5); p->push("h"); p->push("e"); p->push("l"); char elem=0; if(p->stackempty()){} if(p->stackfull()){} cout<<p->stacklenght()<<endl; delete p; p=NULL; system("pause"); return 0; }
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 1312 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號