// Stack1.cpp: implementation of the Stack class. // ////////////////////////////////////////////////////////////////////// #include "Stack.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Stack::Stack() { } Stack::~Stack() { } Stack::set(Node *p_Node1) { // Set the top value to the stack. Top=p_Node1; } Stack::set() { Top=NULL; } Stack::push(Node *p_Node1) { // Insert a card on the top of the stack. p_Node1->next=Top; Top=p_Node1; } Stack::concatenation(Stack stack_in) { // // Insert a stack stack_in in the bottom of the original stack. // // *this=*this + stack_in; // int number_of_elements=0; Node *topTemp, *topPrevious; int x; // if(stack_in.Top!=NULL) { topTemp=Top; while(topTemp!=NULL) { number_of_elements++; topPrevious=topTemp; topTemp=topTemp->next; } x=17; } else { Top= stack_in.Top; } // ------------------------------------------- topPrevious->next=stack_in.Top; } Node* Stack::pop() { // delete a card from the top of the stack. Node *p_Node1; p_Node1=Top; Top=Top->next; return p_Node1; } Stack::show() { if(Top!=NULL) { cout << "The Stack: ==============" << endl; Node * topTemp; topTemp=Top; while(topTemp!=NULL) { topTemp->show(); topTemp=topTemp->next; } } else { cout << "Empty Stack ==============" << endl; } } int Stack::count() { int number_of_elements; number_of_elements=0; if(Top!=NULL) { Node *topTemp; topTemp=Top; while(topTemp!=NULL) { number_of_elements++; topTemp=topTemp->next; } } return number_of_elements; } Stack::reverse() { int number_of_elements; number_of_elements=0; if(Top!=NULL) { Node *topTemp; topTemp=Top; while(topTemp!=NULL) { number_of_elements++; topTemp->side=1-topTemp->side; topTemp=topTemp->next; } } return number_of_elements; }