MENU
Question -

Write member functions to perform POP and PUSH operations in a dynamically allocated stack containing the objects of the following structure:

struct Game
 { char Gamename[30];
 int numofplayer;
 Game *next; } ;



Answer -

struct Game
 {
 char Gamename[3 0] ;
 int numofplayer;
 Game *next;
 };
 class Stack { Game *Top;
 public :
 Stack ()
 {
 Top = NULL;
 }
 void Push();
 void Pop();
 void display();
 -Stack();
 } ;
 void Stack::Push()
 {
 Game *temp = new Game;
 cout<<"Enter Data : "; gets(temp->Gamename);
 cin>>temp->numofplayer;
 temp->next =Top;
 Top = temp;
 }
 void Stack:: Pop()
 {
 if ( Top != NULL)
 {
 Game *temp = Top;
 coutnext;
 delete temp;
 }
 else
 cout<<"Stack is empty....";
 }

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×