class stack
{
private :
T arr[MAX] ;
int top ;
public :
stack( ) ;
int empty();
void push ( T item ) ;
T pop(void ) ;
void print(void);
void clear();
~stack();
} ;
I have implemented this in sat1.h.
This is the class of stack , I wrote. T is the type like int , etc. This can be tested as:
#include <iostream>
#include<conio.h>
#include <sat1.h>
using namespace std;
int main( )
{
stack<int> s ;
int i=0; /*it is very imprttant to initialise the i value otherwise u will get the error that "prgm is insantiated "at the
line i=s.pop();*/
s.push ( 11 ) ;
s.push ( 23 ) ;
s.push ( -8 ) ;
s.push ( 16 ) ;
s.push ( 27 ) ;
s.push ( 14 ) ;
s.push ( 20 ) ;
s.push ( 39 ) ;
s.push ( 2 ) ;
s.push ( 15 ) ;
s.push ( 7 ) ;
s.print();
i=s.pop();
cout << "\n\nItem popped: " << i ;
i = s.pop( ) ;
cout << "\nItem popped: " << i ;
i = s.pop( ) ;
cout << "\nItem popped: " << i ;
i = s.pop( ) ;
cout << "\nItem popped: " << i ;
i = s.pop( ) ;
cout << "\nItem popped: " << i ;
s.print();
getch();
return 0;
}
Blogged with the Flock Browser
No comments:
Post a Comment