/ * stack.h * / # iFNDef __sqstack_h __ # define __sqstack_h__ 1
#include
Extern "C" {void exit (int);}
const Int ndefaultstacksize = 50; // The number of STACK elements
/ / The following sequential storage structure (sequential stack) C class definition template
"<< endl; exit (1);} stacksize = INITSIZE; // Initialization stack size TOP = -1; // Initialization Stack top position} // Destructure function ~ stack () {if (stacklist) delete [] stacklist Stacksize = 0; TOP = -1;} // Decision stack is empty int Stackempty () const {return top <0; // TOP == -1;} // Judgment Whether stack full stckfull () const { Return Top == Stacksize - 1;} // Return to the element in the stack int Stocklength () const {return Top 1;} // Stack Void Push (const t & item) {if (TOP> = stacksize - 1) {CERR << "The stack is full, and it is impossible to continue the stack operation! "<< Endl; Return;} TOP ; // Modify the top position (subscript) stacklist [TOP] = item; // Type T requires support = operator} // out of the stack T POP () {t temp ; If (TOP> = 0) {TEMP = stacklist [TOP]; // Transfer Stack Top Element Value Top -; // Modify Stack Top Location} Else Cerr << "The stack is empty and cannot continue from the stack operation ! "<< endl; returnization;} // read the top element T peek () const {t returnvalue; if (top> = 0) ReturnValue = stacklist [top]; else cerr <<" stack is empty, unread Take the top element! "<< Endl; Return ReturnValue;} // Clear Stack Void ClearsTack () {TOP = -1; // Top Location Reset}}
// convert the decimal number NUM into TOSYS (2-36) enrollment value (deposit Destnum in a string and return) char * decimalconversion (unsigned long Num, unsigned char TOSYS, CHAR DESTNUM []) {IF ( ! destnum) Return NULL; Stack
// stacktest.cpp # incrude
Void main () {stack
Char s [80]; cout << Decimalconversion (1024, 2, s) << endl;}