Stack using Linked list
#include "process.h"
#include "iostream.h"
struct node
{
int info;
node *next;
};
class stack
{
public :
node *top;
stack ()
{
top = NULL;
}
void push ();
void pop ();
void display (node *t);
};
void stack :: push ()
{
node *n;
n = new node;
cout << "enter the element \n”;
cin >> n->info;
n->next = top;
top = n;
}
void stack::pop()
{
node *n;
if (top == NULL)
cout << "stack is empty " <<< "the poped element is "
top = top->next;
}
}
void stack :: display(node *t)
{
cout<<" "
display (t->next);
}
void main ()
{
stack s;
int choice;
while (1){
cout<<"1.push 2.pop 3.display 4.exit"<<'\n'; cin>>choice;
switch(choice)
{ case 1 : s.push (); break;
case 2 : s.pop (); break;
case 3 : s.display(s.top); break;
case 4 : exit(0);
}
}
}
Tuesday, May 25, 2010
Source code For Stack implementation using linked list in C++
Posted by Janaki Narayanamma P at 8:13 PM
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment