c 棧 編寫類實現簡單的棧,c 棧 編寫乙個類實現簡單的棧

時間 2022-01-09 09:35:08

1樓:宋浩飛惠君

#include

using

namespace

std;

class

stack

bool

push(int

n)//壓棧

bool

pop()//退棧

intgettop()//得到棧頂元素

bool

isempty()//判斷是否為空

bool

isfull()//判斷是否已滿

private:

intdata[10];

inttop;

};int

main()

if(!s.push(12))//將12入棧;

if(!s.push(14))//將14入棧;

cout<

s.pop();//退棧

cout<

}如上類,這是可以儲存10個整型數空間的棧。

2樓:匿名使用者

#include

using namespace std;

#define stacksize 100typedef char datatype;

void error(char* _pchmessage);

typedef class cstack

seqstack;

cstack::cstack()

m_ntop = -1;

}cstack::~cstack()

void cstack::initstack()m_ntop = -1;

}int cstack::stackempty()int cstack::stackfull()void cstack::pushstack(datatype _temp)

m_data[++m_ntop] = _temp;

}datatype cstack::popstack()return m_data[m_ntop--];

}datatype cstack::stacktop()return m_data[m_ntop];

}void cstack::showstack()else }

}int main()

if(pstack->stackfull())pstack->pushstack('a');

pstack->pushstack('b');

pstack->pushstack('c');

pstack->pushstack('d');

pstack->pushstack('e');

cout << "popstack = " << pstack->popstack() << endl;

cout << "stacktop = " << pstack->stacktop() << endl;

pstack->showstack();

delete pstack;

pstack = null;

return 0;

}void error(char* _pchmessage)

用乙個棧實現另乙個棧的排序 25

編寫C源程式,其中包含順序表示的空棧的建立 判斷棧是否為

1,如何斷棧是否為空 c 中 stack 類的count 屬性 返回就是堆疊的長度。system.collections.stack stack new system.collections.stack stack.push 1 if 0 stack.count messagebox.show 堆疊...

c 怎麼用棧實現運算子的優先順序比較?

首先肯定要設計棧的資料結構,之後設計運算子操作類,這是整體思路。include using namespace std template class stack maxsize n top 1 stack stack maxsize n top 1 template void stack frees...

C 程式棧空間的使用問題不是很理解

這是典型的位址引用和值引用的區別,通俗地講就是乙個傳位址,乙個傳值。傳位址的函式對位址指向的內容做處理,那麼該位址指的東西就變了,所以不需要返回值 而傳值函式僅對數值處理,也就是對別的位址處理,需要有返回值。somefn這個函式就是傳位址的。看了一下,這個例子是要說明不能返回區域性變數的位址 就是那...