- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path22.stack.cpp
More file actions
Latest commit
143 lines (135 loc) · 2.39 KB
/
Copy path22.stack.cpp
File metadata and controls
143 lines (135 loc) · 2.39 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include<iostream>
#include<cstdlib>
//define max
#definemax10
usingnamespacestd;
//declare struct with 2 attr
structstack
{
int top;
int data[max];
} stacked;
// int type func declare
intfull();
intempty();
//void type func declare
voidinput(int data);
voidfirst();
voidshow();
voidclean();
voiddeleteStack();
intmain()
{
int choice,data;
first();
do{
cout<<"Stacking C++ Example\n";
cout<<"1.Input\n";
cout<<"2.Hapus\n";
cout<<"3.Show Data\n";
cout<<"4.Clear Data\n";
cout<<"5.Exit\n\n";
cout<<"masukkan pilihan anda = ";
cin>>choice;
switch (choice)
{
case1 :
cout<<"Masukkan Data = ";
cin>>data;
input(data);
break;
case2 :
deleteStack();
break;
case3 :
show();
break;
case4 :
clean();
break;
case5 :
cout<<"Terimakasih !";
default:
break;
}
}while (choice!=5);
}
intfull()
{
if (stacked.top == max - 1)
{
returntrue;
}
else
{
returnfalse;
}
}
intempty()
{
if (stacked.top == -1)
{
returntrue;
}
else
{
returnfalse;
}
}
voidinput(int x)
{
if (empty())
{
stacked.top++;
stacked.data[stacked.top] = x;
system("cls");
cout << "data " << stacked.data[stacked.top] << " Telah Masuk ke stack!\n";
}
elseif (!full())
{
stacked.top++;
stacked.data[stacked.top] = x;
system("cls");
cout << "data " << stacked.data[stacked.top] << " Telah Masuk ke stack!\n";
}
else
{
system("cls");
cout << "Stack Telah penuh !\n";
}
}
voidfirst()
{
stacked.top = -1;
}
voidshow()
{
if(!empty()){
system("cls");
for(int x =stacked.top;x>=0;x--){
cout<<"Tumpukan ke "<<x+1<<" = "<<stacked.data[x]<<endl;
}
}
else{
system("cls");
cout<<"Tumpukan Kosong!\n";
}
}
voidclean()
{
stacked.top=-1;
system("cls");
cout<<"Stack Telah Kosong!\n";
}
voiddeleteStack()
{
if(!empty()){
system("cls");
cout<<"Data Teratas Sudah Diambil\n";
stacked.top--;
}
else{
system("cls");
cout<<"Data Kosong!\n";
}
}