-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCQueque.py
More file actions
124 lines (102 loc) · 3.64 KB
/
CQueque.py
File metadata and controls
124 lines (102 loc) · 3.64 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
from collections import deque
import Reader as r
# Queque variables
colaRound = [" ", " ", " ", " ", " ", " "]
QuequeSize = 6
ToQueque = ""
# checks if Round Queque is "full", if not then returns False
def isQuequeFull():
ItemsOnQueque = 0
for x in range(QuequeSize):
if colaRound[x] != " ":
ItemsOnQueque += 1
if ItemsOnQueque == QuequeSize:
Status = True
else:
Status = False
return Status
# checks if Round Queque is "empty", if not then returns False
def isQuequeEmpty():
SpaceOnQueque = 0
for x in range(QuequeSize):
if colaRound[x] == " ":
SpaceOnQueque += 1
if SpaceOnQueque == QuequeSize:
Status = True
else:
Status = False
print(f"is Empty: {Status}; Items: {SpaceOnQueque}")
return Status
#circular queque
def ColaCircular():
# choice and output variables
choice = 0
Restr = ""
# Arrow control variables
FrontPointer = ""
RearPointer = ""
RearIndex = 0
FrontIndex = 0
while True:
if (Restr == ""):
Items = 0
# passes elements on list to string that is going to be printted
for x in range(QuequeSize):
Restr += ("[" + colaRound[x] + "]")
# controls Front arrow position
FrontPointer = ((" " * (FrontIndex * 4)) + "▼▼")
FrontPointer += (" " * (22 - len(FrontPointer)))
# controls Rear arrow position
RearPointer = ((" " * (RearIndex * 4)) + "▲▲")
RearPointer += (" " * (22 - len(RearPointer)))
else:
# error in flow
FrontPointer = ("▼" * 22)
RearPointer = ("▲" * 22)
Restr += (" " * (24 - len(Restr)))
print(f'''
┌─────────────────────────────────┐
│ COLA CIRCULAR │
├────────────────────────┬────────┤
│ {FrontPointer} │ FINAL │
│''' + Restr + f'''├────────┤
│ {RearPointer} │ FRENTE │
├────────────────────────┼────────┘
│ 1] VER COLA │
│ 2] AGREGAR ELEMENTO │
│ 3] QUITAR ELEMENTO │
│ 0] SALIR │
└────────────────────────┘''')
choice = r.ReadInt(0, 3)
Restr = ""
if (choice == 1):
continue
elif (choice == 2):
if not isQuequeFull():
print("[AGREGAR ELEMENTO]")
while True:
ToQueque = input("[2 CARACTERES MAX]: ")
if (len(ToQueque) < 3 and (ToQueque != "")):
if(len(ToQueque) == 1):
ToQueque += " "
colaRound[FrontIndex] = ToQueque
break
# index counter
FrontIndex += 1
if (FrontIndex == 6):
FrontIndex = 0
else:
Restr = " OVERFLOW ERROR"
elif (choice == 3):
if not (isQuequeEmpty()):
print("[QUITAR ELEMENTO] (" + colaRound[RearIndex] + ")")
colaRound[RearIndex] = " "
#index counter
RearIndex += 1
if (RearIndex == 6):
RearIndex = 0
else:
Restr = " UNDERFLOW ERROR"
elif (choice == 0):
print("VOLVIENDO A MENU...")
break