Answers for "stck overflow python queue"

0

stck overflow python queue

class Queue:
        def __init__(self,no):
            self.no = no 
            self.SQueue = []
            self.front = -1
            self.rear = -1
        def insert(self):
            if self.rear == self.no -1:
                print("Queue is Full.....")
            else:           
                if self.front == -1:
                    self.front = 0
                    self.rear = 0
                else :
                    self.rear += 1
                n = int(input("enter an element :: "))
                self.SQueue.insert(self.rear, n)
    
        def delete(self):
            if self.front == -1 and self.front == no - 1:
                print("Queue is Empty.....")
            else:
                self.SQueue.pop(self.front)
                self.front +=1
        def disp(self):
            if self.front == -1 and self.front == no - 1:
                print("Queue is Empty.....")
            else:
                print("REAR \tELEMENT")
                for i in range(len(self.SQueue)):
                    print(i," \t",self.SQueue[i])
    
    no = int(input("ENTER  Size :: "))
    q = Queue(no)
    while(True):
        print(" 1: INSERT ")
        print(" 2: DELETE ")
        print(" 3: PRINT ")
        print(" 4: EXIT ")
        option = int(input("enter your choice :: "))
    
        if option == 1:
            q.insert()
     
        elif option == 2:
            q.delete()
    
        elif option == 3:
            q.disp()
    
        elif option == 4:
            print("you are exit!!!!!")
            break
        else:
            print("Incorrect option")
Posted by: Guest on June-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language