// Stack.cpp: implementation of the Stack class. // ////////////////////////////////////////////////////////////////////// #include #include "Stack.h" #define NULL 0 ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// Stack::Stack() { Top=NULL; } void Stack::copy(Stack &stack1) { int number_of_elements=0; Node *nodeLocal; Node *topTemp0, *topPrevious0; Node *topTemp1; if(&stack1==NULL) { return; } if(stack1.Top==NULL) { Top=NULL; return; } nodeLocal=new Node; Top=nodeLocal; topTemp1=stack1.Top; topTemp0=Top; while(topTemp1!=NULL) { number_of_elements++; *nodeLocal=*topTemp1; nodeLocal=new Node; topPrevious0=topTemp0; topTemp0->next=nodeLocal; topTemp0=topTemp0->next; topTemp1=topTemp1->next; } topPrevious0->next=NULL; } Stack::~Stack() { } void Stack:: operator+(Node& node1) { // Concatenate the original stack with the node. // First comes the stack and next the node. int number_of_elements=0; Node *topTemp, *topPrevious; int x; // Append a node to a stack. if(&node1==NULL) { return; } if(Top==NULL) { Top=&node1; return; } // //1 topTemp=&node1; topTemp=Top; while(topTemp!=NULL) { number_of_elements++; topPrevious=topTemp; topTemp=topTemp->next; } x=17; // ------------------------------------------- //1 topPrevious->next=Top; //1 Top=&node1; topPrevious->next=&node1; return; } void Stack:: operator+(Stack& stack1) { // Concatenate the original stack with the Stack stack1. // First comes the stack and next the stack1. int number_of_elements=0; Node *topTemp, *topPrevious; int x; // Append a node to a stack. if(&stack1==NULL) { return; } if(Top==NULL) { Top=stack1.Top; return; } // topTemp=Top; while(topTemp!=NULL) { number_of_elements++; topPrevious=topTemp; topTemp=topTemp->next; } x=17; // ------------------------------------------- //p_Node1->next=Top; topPrevious->next=stack1.Top; return; } Stack:: operator=(Stack& stack1) { // Assignment of a stack Top=stack1.Top; } Stack:: operator=(Node& node1) { // Assignment of a Node Top=& 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; }