Skip to content

Commit 07e8e25

Browse files
authored
Merge pull request #190 from jyotsana19/master
Added Dequeue in Python
2 parents 8f3abf5 + fb347ac commit 07e8e25

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: data_structures/Queue/DeQueue.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Python code to demonstrate working of
2+
# extend(), extendleft(), rotate(), reverse()
3+
4+
# importing "collections" for deque operations
5+
import collections
6+
7+
# initializing deque
8+
de = collections.deque([1, 2, 3,])
9+
10+
# using extend() to add numbers to right end
11+
# adds 4,5,6 to right end
12+
de.extend([4,5,6])
13+
14+
# printing modified deque
15+
print ("The deque after extending deque at end is : ")
16+
print (de)
17+
18+
# using extendleft() to add numbers to left end
19+
# adds 7,8,9 to right end
20+
de.extendleft([7,8,9])
21+
22+
# printing modified deque
23+
print ("The deque after extending deque at beginning is : ")
24+
print (de)
25+
26+
# using rotate() to rotate the deque
27+
# rotates by 3 to left
28+
de.rotate(-3)
29+
30+
# printing modified deque
31+
print ("The deque after rotating deque is : ")
32+
print (de)
33+
34+
# using reverse() to reverse the deque
35+
de.reverse()
36+
37+
# printing modified deque
38+
print ("The deque after reversing deque is : ")
39+
print (de)

0 commit comments

Comments
 (0)