FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-algorithms/data-structures/dequeue.py at master · Samguy1/python-algorithms · GitHub
Samguy1
/
python-algorithms
Public
forked from
AllAlgorithms/python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-algorithms
/
data-structures
/
dequeue.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (39 loc) · 1.08 KB
Breadcrumbs
python-algorithms
/
data-structures
/
dequeue.py
Copy path
File metadata and controls
48 lines (39 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
class
Dequeue
:
def
__init__
(
self
):
self
.
items
=
[]
def
is_empty
(
self
):
return
self
.
items
==
[]
def
append
(
self
,
data
):
self
.
items
.
append
(
data
)
def
append_left
(
self
,
data
):
self
.
items
.
insert
(
0
,
data
)
def
pop
(
self
):
return
self
.
items
.
pop
()
def
pop_left
(
self
):
return
self
.
items
.
pop
(
0
)
q
=
Dequeue
()
print
(
'Menu'
)
print
(
'append <value>'
)
print
(
'appendleft <value>'
)
print
(
'pop'
)
print
(
'popleft'
)
print
(
'quit'
)
while
True
:
do
=
input
(
'What would you like to do? '
).
split
()
operation
=
do
[
0
].
strip
().
lower
()
if
operation
==
'append'
:
q
.
append
(
int
(
do
[
1
]))
elif
operation
==
'appendleft'
:
q
.
append_left
(
int
(
do
[
1
]))
elif
operation
==
'pop'
:
if
q
.
is_empty
():
print
(
'Dequeue is empty.'
)
else
:
print
(
'Popped value from right: '
,
q
.
pop
())
elif
operation
==
'popleft'
:
if
q
.
is_empty
():
print
(
'Dequeue is empty.'
)
else
:
print
(
'Popped value from left: '
,
q
.
pop_left
())
elif
operation
==
'quit'
:
break
Back
|
FazBrowse Home
|
New Git URL