// Implementation of the chain stack-big talk Data Structure 99 pages # include <iostream> using namespace STD; // The chain node defines typedef struct stacknode {int data; struct stacknode * Next ;} stacknode, * linkstackptr; // defines the chain stack, header pointer and length struct linkstack {linkstackptr top; int count ;};
// Initialization
Void initstack (linkstack * l ){
L-> Top = NULL;
L-> COUNT = 0;
}
// Int push (linkstack * l, int e) {linkstackptr S = new stacknode; // apply for memory S-> DATA = e for the new element; // put the data to be inserted into the data S-> next = L-> top of the applied node; // put the data in the top node into the next L-> Top = s; // assign s to top L-> count ++; // The number of data plus a return 0; // normal termination} int POP (linkstack * l) {linkstackptr P; if (L-> Top = NULL) // determines whether it is null. If it is null, the return-1; int e; E = L-> top-> data; // top refers to the top data of the stack P = L-> top; // top is assigned to p l-> Top = L-> top-> next; // big case data structure 99 pages free (p); // release p l-> count --; // subtract one return E from the data; // return the output stack data}
// Destroy the stack
Void destroystack (linkstack * l) {linkstackptr Q; while (L-> count) {q = L-> top-> next; delete L-> top; l-> Top = Q; L-> count --;} cout <"destroyed successfully" <Endl ;}
void main(){ LinkStack a;
InitStack(&a); Push(&a,3); Push(&a,4); Push(&a,5); cout<<Pop(&a)<<endl; cout<<Pop(&a)<<endl; cout<<Pop(&a)<<endl;}
Chain Stack -- (97 pages of big talk data structure)