Array implementation of stack

Here will discuss the array implementation of stack. Problems with array implementation Underflow - Array may be empty but people may try to pop the element Overflow - Array is full. To over come we have to use re-szing of array. We can see how we can solve this problem here - http://k2code.blogspot.com/2013/09/resizing-array-implementation-of-stack.html Null items - Can nulls be added - Yes in this case, nulls can be added in stack Loitering (java specific) - Holding a reference to an object wen it is no longer needed. To over come this we should explicitly set array index to null. For eg. ...

Array implementation of stack

Here will discuss the array implementation of stack. Problems with array implementation Underflow - Array may be empty but people may try to pop the element Overflow - Array is full. To over come we have to use re-szing of array. We can see how we can solve this problem here - http://k2code.blogspot.com/2013/09/resizing-array-implementation-of-stack.html Null items - Can nulls be added - Yes in this case, nulls can be added in stack Loitering (java specific) - Holding a reference to an object wen it is no longer needed. To over come this we should explicitly set array index to null. For eg. ...

Stack implementation using linked list

We will be understanding the stack implementation using linked list. So, please understand the link list before proceeding. Lets understand how we can implement the different operation using linked list. CPP implementation Here is how we use linked list to implement stack in cpp: #include <iostream> using namespace std; struct node { int info; struct node \*next; }; struct node \*top; int empty() { return((top == NULL)? 1:0); } void push(int n) { struct node \*p; p=new node; if(p!=NULL) { p->info=n; p->next=top; top=p; } else cout<<"Not inserted,No memory available"; } int pop() { struct node \*temp; int x; x=top->info; temp=top; top=top->next; free(temp); return(x); } void print() { int i =0; struct node \* temp; temp = top; cout<<"\\n\\t\\t"; if(temp==NULL) cout<<"\\n\\t\\tNo elements\\n"; else { while(temp!=NULL) { int info = temp->info; cout<info<<" "; temp=temp->next; } cout<<"End of List<<"\\n"; } } ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy