Presentation is loading. Please wait.

Presentation is loading. Please wait.

Stacks Using Linked Lists Here, we use the same concept of the stack but eliminate the MAXIMUM data items constraint. Since we shall be using Linked Lists.

Similar presentations


Presentation on theme: "Stacks Using Linked Lists Here, we use the same concept of the stack but eliminate the MAXIMUM data items constraint. Since we shall be using Linked Lists."— Presentation transcript:

1 Stacks Using Linked Lists Here, we use the same concept of the stack but eliminate the MAXIMUM data items constraint. Since we shall be using Linked Lists to store data in the stack, the Stack can hold as much as data as it wants as long as the data is within Memory Limits A top BC Push and POP are done here.

2 Node A datapointer node #include struct node { int data; node *link; };

3 class lstack { private: node* top; public: lstack(); void push(int n); int pop(); ~lstack(); }; A Simple Linked List Stack Class

4 Constructor lstack::lstack() { top=NULL; }

5 Push( ) Function void lstack::push(int n) { node *tmp; tmp=new node; if(tmp==NULL) cout data=n; tmp->link=top; top=tmp; }

6 Pop( ) Function int lstack::pop() { if(top==NULL) { cout data; top=top->link; delete tmp; return n; }

7 Destructor Function lstack::~lstack() { if(top==NULL) return; node *tmp; while(top!=NULL) { tmp=top; top=top->link; delete tmp; } }


Download ppt "Stacks Using Linked Lists Here, we use the same concept of the stack but eliminate the MAXIMUM data items constraint. Since we shall be using Linked Lists."

Similar presentations


Ads by Google