Skip to main content

Posts

Showing posts from January, 2017

Stack using Class,Array and Pointer

#include<iostream> using namespace std; class stack {  public:      stack(int num){   top=-1;   max=num;   a=new int[max];  };    void push();  void pop();  void display(); private: int top; int max; int input; int *a;  };  void stack::push() {  if(top==max-1)  {   cout<<"stack is overflow"<<endl;  }  else  {   cout<<"Enter the Element in the Stack"<<endl;   cin>>input;   top=top+1;   a[top]=input;  }  }  void stack::pop() {  if(top==-1)  {  cout<<"Stack is Empty"<<endl;  }  else  {  cout<<"Stack value : "<<a[top]<<endl;  top=top-1;  } } void stack::display() { if(top==-1)  {  cout<<"Stack is Empty"<<endl;  }  else  {for(int i=top; i>=0; i--)  {   cout<<"Stack["<<i<<"] : "<<a[i]<<endl;  }  } } int main() { int data; cout<<"Enter the max len of Stack"<<endl; cin>>data; stack *stk=

Stack using Array

#include<iostream> using namespace std; #define max 5 int a[max]; int top=-1; int input; void push() {  if(top==max-1)  {   cout<<"stack is overflow"<<endl;  }  else  {   cout<<"Enter the Element in the Stack"<<endl;   cin>>input;   top=top+1;   a[top]=input;  }  } void pop() {  if(top==-1)  {  cout<<"Stack is Empty"<<endl;  }  else  {  cout<<"Stack value : "<<a[top]<<endl;  top=top-1;  } } void display() { if(top==-1)  {  cout<<"Stack is Empty"<<endl;  }  else  {for(int i=top; i>=0; i--)  {   cout<<"Stack["<<i<<"] : "<<a[i]<<endl;  }  } } int main() { int select; char again; do{   cout<<"***** 1.PUSH ****"<<endl;   cout<<"***** 2.POP ****"<<endl;   cout<<"***** 3.Display ****"<<endl;   cout<<"Select the option"<<endl;