-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-stack-quiz.cpp
More file actions
33 lines (27 loc) · 856 Bytes
/
14-stack-quiz.cpp
File metadata and controls
33 lines (27 loc) · 856 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
#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 setelah pop
cout << "Elemen teratas saat ini : " << parkirMotor.top() <<endl;
cout <<"============================="<< endl;
// Cek apakah stack ada isi, tidak kosong
while (!parkirMotor.empty()) {
if(parkirMotor.top()!= "CBR"){
parkirMotor.pop();
}else{
cout <<"Motor " << parkirMotor.top() << " Siap Meluncur.. cihuyy ";
break;
}
}
return 0;
}