stck overflow python queue

Solutions on MaxInterview for stck overflow python queue by the best coders in the world

showing results for - "stck overflow python queue"
Lotta
14 Apr 2019
1    class Queue:
2        def __init__(self,no):
3            self.no = no 
4            self.SQueue = []
5            self.front = -1
6            self.rear = -1
7        def insert(self):
8            if self.rear == self.no -1:
9                print("Queue is Full.....")
10            else:           
11                if self.front == -1:
12                    self.front = 0
13                    self.rear = 0
14                else :
15                    self.rear += 1
16                n = int(input("enter an element :: "))
17                self.SQueue.insert(self.rear, n)
18    
19        def delete(self):
20            if self.front == -1 and self.front == no - 1:
21                print("Queue is Empty.....")
22            else:
23                self.SQueue.pop(self.front)
24                self.front +=1
25        def disp(self):
26            if self.front == -1 and self.front == no - 1:
27                print("Queue is Empty.....")
28            else:
29                print("REAR \tELEMENT")
30                for i in range(len(self.SQueue)):
31                    print(i," \t",self.SQueue[i])
32    
33    no = int(input("ENTER  Size :: "))
34    q = Queue(no)
35    while(True):
36        print(" 1: INSERT ")
37        print(" 2: DELETE ")
38        print(" 3: PRINT ")
39        print(" 4: EXIT ")
40        option = int(input("enter your choice :: "))
41    
42        if option == 1:
43            q.insert()
44     
45        elif option == 2:
46            q.delete()
47    
48        elif option == 3:
49            q.disp()
50    
51        elif option == 4:
52            print("you are exit!!!!!")
53            break
54        else:
55            print("Incorrect option")
56     
57
58
59
60