STACK_PUSH_POP

STACK OPERATION PUSH & POP

HOME
/*..PROGRAM
TO REVERSE THE STRING

 USING
STACK WITH LINKED REPRESENATION

  
AND SELF REFERENTION CLASSES… ..*/


#include<iostream.h>
class
stack //CLASS
DECLARATION

{
private:
  
 char data;

  
 stack *next;

public:
  
 void push(char);

  
 void pop();

}
*top;

//FUNCTION
FOR PUSHING DATA

void
stack::push(char ch)

{
  
 stack *n,*temp;

  
 n=new(stack);

  
 n->data=ch;

  
 n->next=NULL;

  
 if(top==NULL)

  
     top=n;

  
 else

  
 {

  
 temp=top;

  
  n->next=temp;

  
 top=n;

  
 }

}
//FUNCTION
FOR POPPING DATA

void
stack::pop()

{
  
 stack *temp,*t;

  
 temp=top;

  
 while(temp!=NULL)

  
 {

  
 cout<<temp->data<<” “;

  
 t=top;

  
 top=temp->next;

  
 temp=temp->next;

  
 delete t;

  
     

  
 }

}
void
main()//MAIN()
FUNCTION STARTS

{
  
 char x[22];

  
 top=NULL;

  
 stack s;//OBJECT
CREATION

cout<<“ENTER
THE STRING

       
TO BE PUSHED INTO THE STACK\n”;

  
 cin>>x;

  
 for(int i=0;x[i]!=”;i++)

  
     s.push(x[i]);

  
 

cout<<“AFTER
POPPING THE STRING IS\n”;

  
       
 s.pop();

  
 

}//END OF MAIN()

//PROGRAM
ENDS

/*
OUTPUT:

ENTER
THE STRING   BHANU

THE
STRING IN THE REVERSE ORDER

UNAHB
Press
any key to continue*/

HOME

Advertisements

5 Comments »

  1. 1
    bhargav Says:

    keep on trying more blogs

  2. 2
    mushi Says:

    appearance is superb
    need to keep more info. inaddition to code

  3. 3
    J Devendra Says:

    Nice…

    Continue the concept of uploading data….

  4. 4
    rajendra Says:

    very good
    program is nice

  5. 5
    subbu Says:

    it’s nice
    but keep data inaddition to programming code


RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: