File tree Expand file tree Collapse file tree 1 file changed +111
-0
lines changed Expand file tree Collapse file tree 1 file changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ AUTHOR: Robin Singh
3
+ IMPLEMENTATION OF DOUBLE ENDED QUEUE
4
+
5
+ """
6
+
7
+ class DoubleEnded :
8
+ def __init__ (self ,lenght = 5 ):#Change according to you
9
+ self .items = []
10
+ self .length = lenght
11
+
12
+ def isFull (self ):
13
+ if len (self .items ) == self .length :
14
+ return True
15
+ else :
16
+ return False
17
+
18
+ def isEmpty (self ):
19
+ if self .items == []:
20
+ return True
21
+ else :
22
+ return False
23
+
24
+ def Enqueue_start (self ,ele ):
25
+ if (self .isFull ()):
26
+ return True
27
+ else :
28
+ self .items .insert (0 ,ele )
29
+ def Enqueue_End (self ,ele ):
30
+ if (self .isFull ()):
31
+ return True
32
+ else :
33
+ self .items .append (ele )
34
+
35
+ def Dequeue_start (self ):
36
+ if (self .isEmpty ()):
37
+ return True
38
+ else :
39
+ return self .items .pop (0 )
40
+
41
+ def dequeue_End (self ):
42
+ if (self .isEmpty ()):
43
+ return True
44
+ else :
45
+ return self .items .pop ()
46
+
47
+ def display (self ):
48
+ if self .items == []:
49
+ return True
50
+ else :
51
+ print (self .items )
52
+
53
+
54
+ if __name__ == '__main__' :
55
+ a = DoubleEnded ()
56
+ while (1 ):
57
+
58
+ print (f"\n 1.Enqueue START \t 2.Enqueue End \t 3.Dequeue Start \t 4.Dequeue End\t 5.Display\t 6.Exit" )
59
+ ch = int (input ("entre ur choice" ))
60
+ if ch == 6 :
61
+ break
62
+
63
+ elif ch == 1 :
64
+ ele = int (input ("Entre Element to be pushed At START" ))
65
+ if (a .Enqueue_start (ele )):
66
+ print ("Queue Overflown" )
67
+ else :
68
+ a .display ()
69
+
70
+
71
+ elif ch == 2 :
72
+
73
+ ele = int (input ("Entre Element to be pushed at END" ))
74
+
75
+ if (a .Enqueue_End (ele )):
76
+ print ("Queue Overflown" )
77
+
78
+ else :
79
+
80
+ a .display ()
81
+
82
+
83
+ elif ch == 3 :
84
+ t = a .Dequeue_start ()
85
+ if t == 1 :
86
+ print ("Queue Is Empty,Insert Number" )
87
+ else :
88
+ print (f"Dequeued value = { t } " )
89
+ a .display ()
90
+
91
+
92
+ elif ch == 4 :
93
+
94
+ t = a .dequeue_End ()
95
+
96
+ if t == 1 :
97
+
98
+ print ("Queue Is Empty,Insert Number" )
99
+
100
+ else :
101
+
102
+ print (f"Dequeued value = { t } " )
103
+
104
+ a .display ()
105
+
106
+
107
+ elif ch == 5 :
108
+ a .display ()
109
+
110
+ else :
111
+ print ("INVALID OPTION" )
You can’t perform that action at this time.
0 commit comments