temlate stack using linked problems in output

xenoglaux's Avatar, Join Date: Jan 2009
Light Poster
Code:
 
#include <iostream.h>
#include<stdlib.h>
#include<conio.h>
struct node
{    
int data;
    struct node *link;
    };
    struct node *top=NULL,*temp;
    void main()
    {    int choice,data;
        
                while(1)//infinite loop is used to insert/delete infinite number of nodes    
                {                cout << "\n1.Push\n2.Pop\n3.Display\n4.Exit\n";        
                cout << "\nEnter ur choice:";        
                cin >> choice;        
                switch(choice)        
{  case 1:
            temp=(struct node *)malloc(sizeof(struct node));
            cout << "Enter a node data :";
            cin >> data;
            temp->data=data;
            temp->link=top;
            top=temp;   
                                                        
break;   
                                                        
    case 2:    
            if(top!=NULL)           
         {   
                          
           cout << "The poped element is " << data,top->data;
         
            top=top->link;            
         }          
            else           
          {        cout << "\nStack Underflow";                }  
                      break;   
                                     
    case 3: 
             temp=top;  
             if(temp==NULL)      
    {        cout << "\nStack is empty\n";  }   

                while(temp!=NULL)  
    {               
                cout << "->" <<data << "->",temp->data; 
                   temp=temp->link;            }   
             break; 
                    
    case 4:       
        
            exit(0);        }           
                   
        }  
    }
when i wanna push a number say it 4 6 9 11
n i choose option2 is pop
the element of popped is 11
and again option 2 pop
the element of popped is 11
n if i put display option3
the output is 11->11->11->11->

do you know what's wrong with this?
thanks
xenoglaux's Avatar, Join Date: Jan 2009
Light Poster
Sorry, i post twice...
My bad... How can i remove this article?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Duplicate of linked stack output problems. Thread closed.