-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-stack.cpp
More file actions
38 lines (29 loc) · 968 Bytes
/
14-stack.cpp
File metadata and controls
38 lines (29 loc) · 968 Bytes
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
#include <iostream>
#include <stack> // Header untuk stack
using namespace std;
int main() {
// Deklarasi stack
stack<string> parkirMotor;
// Push (menambahkan elemen ke stack)
parkirMotor.push("Nmax");
parkirMotor.push("Aerox");
parkirMotor.push("CBR");
parkirMotor.push("Ducati");
parkirMotor.push("Vespa");
cout << "Ukuran stack saat ini: " << parkirMotor.size() <<endl;
// Menampilkan elemen teratas
cout << "Elemen teratas: " << parkirMotor.top() <<endl;
// Pop (menghapus elemen teratas)
cout << "Menghapus elemen teratas..." <<endl;
parkirMotor.pop();
cout<<"=============================="<<endl;
// Menampilkan elemen setelah pop
cout << "Elemen teratas saat ini: " << parkirMotor.top() <<endl;
// Cek apakah stack kosong
if (parkirMotor.empty()) {
cout << "Stack kosong." <<endl;
} else {
cout << "Stack tidak kosong." <<endl;
}
return 0;
}