Sunday 25 September 2011

Reverse string using stack

//this is one of the applications of Stack data structure
#include "stack.cpp" //user defined header file
#include<iostream.h>
#include<conio.h>
void main()
{
 stack<char>obj;
 char a[40];
 cout<<"read a string into array a\n";
 cin.getline(a,40);
 for(int i=0;a[i]!='\o';i++)
  obj.push(a[i]);
 cout<<"reverese of the string is\n";
 while(!obj.isempty())
  cout<<obj.pop();
  //obj.display();
 getch();
}
/*
Note:
Before executing this program, you make you make sure that , you must be defined the stack class and its member function, and same file name you have to include in this program( for example, my stack class file name is stack.cpp, and make the comment for main() in stack program
*/

Basic stack operation

No comments:

Post a Comment