-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path22.stack.cpp
143 lines (135 loc) · 2.39 KB
/
22.stack.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
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
#define max 10
using namespace std;
//declare struct with 2 attr
struct stack
{
int top;
int data[max];
} stacked;
// int type func declare
int full();
int empty();
//void type func declare
void input(int data);
void first();
void show();
void clean();
void deleteStack();
int main()
{
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)
{
case 1 :
cout<<"Masukkan Data = ";
cin>>data;
input(data);
break;
case 2 :
deleteStack();
break;
case 3 :
show();
break;
case 4 :
clean();
break;
case 5 :
cout<<"Terimakasih !";
default:
break;
}
}while (choice!=5);
}
int full()
{
if (stacked.top == max - 1)
{
return true;
}
else
{
return false;
}
}
int empty()
{
if (stacked.top == -1)
{
return true;
}
else
{
return false;
}
}
void input(int x)
{
if (empty())
{
stacked.top++;
stacked.data[stacked.top] = x;
system("cls");
cout << "data " << stacked.data[stacked.top] << " Telah Masuk ke stack!\n";
}
else if (!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";
}
}
void first()
{
stacked.top = -1;
}
void show()
{
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";
}
}
void clean()
{
stacked.top=-1;
system("cls");
cout<<"Stack Telah Kosong!\n";
}
void deleteStack()
{
if(!empty()){
system("cls");
cout<<"Data Teratas Sudah Diambil\n";
stacked.top--;
}
else{
system("cls");
cout<<"Data Kosong!\n";
}
}