-
Notifications
You must be signed in to change notification settings - Fork 2
/
StackDanQueues.py
57 lines (43 loc) · 1.13 KB
/
StackDanQueues.py
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
from collections import deque
print("=" * 5, "CONTOH 1: STACK", "=" * 5)
X = [1, 2, 3, 4, 5, 6]
print("Data Sekarang : ", X)
# Memasukkan Data Baru
X.append(7)
print("Data Masuk : ", 7)
print("Data Sekarang : ", X)
X.append(8)
print("Data Masuk : ", 8)
print("Data Sekarang : ", X)
# Mengeluarkan Data Yang Terakhir
X.pop()
print("Data Sekarang : ", X)
# Stacking
Y = X.pop()
print("Data Keluar : ", Y)
print("Data Sekarang : ", X)
print('\n\n')
#=========================================
print("=" * 5, "CONTOH 2: QUEUE", "=" * 5)
Antrian = deque([1,2,3,4,5])
print("Data Sekarang : ", Antrian)
# Menambahkan Data
Antrian.append(6)
print("Data Masuk : ", 6)
print("Data Sekarang : ", Antrian)
Antrian.append(7)
print("Data Masuk : ", 7)
print("Data Sekarang : ", Antrian)
# Mengurangi Antrian
Z = Antrian.popleft()
print("Data Keluar : ", Z)
print("Data Sekarang : ", Antrian)
Z = Antrian.popleft()
print("Data Keluar : ", Z)
print("Data Sekarang : ", Antrian)
Z = Antrian.popleft()
print("Data Keluar : ", Z)
print("Data Sekarang : ", Antrian)
Antrian.append(8)
print("Data Masuk : ", 8)
print("Data Sekarang : ", Antrian)