-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate5.cpp
More file actions
80 lines (80 loc) · 1.27 KB
/
Copy pathtemplate5.cpp
File metadata and controls
80 lines (80 loc) · 1.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
template<class Ttype>class class_name
{
*body
}
*class_name<type> ob
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
const int size=10;
template<class STACKTYPE>class stack
{
STACKTYPE stck[size];
int tos;
public: stack()
{
tos=-1;
}
void push(STACKTYPE ob);
STACKTYPE pop();
};
template<class STACKTYPE>
void stack<STACKTYPE>::push(STACKTYPE ob)
{
if(tos==size-1)
{
cout<<"stack full"<<endl;
return;
}
++tos;
stck[tos]=ob;
}
template<class STACKTYPE>
STACKTYPE stack<STACKTYPE>::pop()
{
//body
if(tos==-1)
{
cout<<"stack empty\n";
// return ;
exit(0);
}
STACKTYPE ele=stck[tos];
tos--;
return ele;
}
int main()
{
stack<char>s1,s2;
int i;
// s1.push('a');
// s1.push('b');
// s1.push('c');
// s1.push('d');
// s2.push('x');
for(int i=0;i<4;i++)
{
char in;
cin>>in;
s1.push(in);
}
for(int i=0;i<4;i++)
{
cout<<s1.pop()<<endl;
}
//* double
stack<double>d1,d2;
for(int i=0;i<4;i++)
{
double in;
cin>>in;
d1.push(in);
}
for(int i=0;i<4;i++)
{
cout<<d1.pop()<<endl;
}
return 0;
}