User talk:Arvi2hot

stack implementation
 * 1) include

using namespace std; class stack { int element; stack *next; public: stack *push(stack*,int); stack *pop(stack*); void stack_display(stack*); }*head,object; stack* stack::push(stack *head,int key) { stack *temp,*temp1; temp1=head; temp=new stack; temp->element=key; if(head==NULL) head=temp; else { while(head->next!=NULL) head=head->next; head->next=temp; head=temp1; } return head; } stack *stack:: pop(stack *head) { stack *temp; if(head!=NULL) { temp=head; if(head->next==NULL) { cout<<"\n The popped element from the stack is :"<element<next->next!=NULL) head=head->next; cout<<"\nThe popped element from the stack is :"<next->element; cout<next=head->next->next; head=temp; return head; } else { cout<<"\n Arvi2hot (talk) 10:29, 17 September 2009 (UTC) Not possible to pop an element from the stack Arvi2hot (talk) 10:29, 17 September 2009 (UTC)"; return head; } } void stack::stack_display(stack *head) { if(head!=NULL) { while(head->next!=NULL) { cout<element<<"->"; head=head->next; } cout<element; cout<>ch; head=NULL; while(1) { switch(ch) { case 1: cout<<"\n"; cout<<"\n Enter the element to be pushed : "; cin>>key; head=object.push(head,key); cout<<"\n The stack after push operation is : "; object.stack_display(head); cout<<"\n"; break; case 2: cout<<"\n\n"; head=object.pop(head); cout<<"\n The stack after pop operation is : "; object.stack_display(head); cout<<"\n\n"; break; case 3: exit(1); default: cout<<"\nEnter the correct choice \n"; break; } cout<<"\n Choose the operation to be performed\n"; cout<<"\n\t 1.Push \n\t 2.Pop \n\t 3.Exit \n"; cin>>ch; } } int main { choice; }