Feedjit

Articles for you

Tuesday, December 31, 2013

C++ Plus Plus Program of Stack Object Oriented Program OOP

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
template<class type>
class stack
{
int top;
type arr[10];
public:
 stack(){top=-1;}
void push(type a)
{
 if(top>=10) {cout<<"\nStack Full\n";}
else
arr[++top]=a;
}
type pop()
{
 if(top<=-1){cout<<"\nEmpty\n";return 0;}
 return arr[top--];
}
bool isempty()
{
 if(top==-1)
  return true;
 return false;
}
bool isfull()
{
 if(top==10)
  return true;
 return false;
}
type topvalue(){return arr[top];}

};
void main()
{
 stack <int>si;

 si.push(34);
 si.push(1);
 si.push(2);
 si.push(56);
 si.push(100);
 cout<<si.pop();
 cout<<endl;
  cout<<si.pop();
   cout<<endl;
   cout<<si.pop();
   cout<<endl;
  cout<<si.pop();
    cout<<endl;
   cout<<si.pop();
    cout<<endl;

   

}

Read More

Articles for you