-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB4_Q1_c.cpp
95 lines (65 loc) · 1.33 KB
/
LAB4_Q1_c.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
using namespace std;
class StackArr{
public:
int a[100];
int t = 0;
void push(int value){
if(t<=100){
a[t+1]=value;
t++;
}
else{
cout<<"Array size is limited"<<endl;
}
}
void pop(){
if (t>0){
a[t]=0;
t=t-1;
}
else
cout<<"Stack has no element."<<endl;
}
int siz(){
return t;
}
bool isEmpty(){
if(t==0) return true;
return false;
}
void top(){
cout<<"Top element: "<<a[t]<<endl;
}
void display(){
for(int i=1;i<=t;i++){
cout<<a[i];
}
cout<<endl;
}
};
int main(){
StackArr s1;
for(int i=1; i<10;i++){
s1.push(i);
s1.display();
}
cout<<"Size: "<<s1.siz()<<endl;
cout<<"isEmpty: "<<s1.isEmpty()<<endl;
s1.top();
cout<<endl;
for(int i=1; i<10;i++){
s1.pop();
s1.display();
}
cout<<"Size: "<<s1.siz()<<endl;
cout<<"isEmpty: "<<s1.isEmpty()<<endl;
s1.top();
StackArr s2;
int n = s1.siz();
for(int i=0;i<n;i++){
s2.a[i]=s1.a[t];
s1.pop();
}
return 0;
}