Q. Write a program that implements three queues namely HighestPr, NormalPr and LowestPr. The program accepts an element along with its priority from the user.
e.g., enter element: KP213
Priority (Highest/ Normal / Lowest (H/N/L): H
As per priority entered, the element is added in the corresponding queue.
A menu offers following options:
1. Insert Element
2. Search for Element
3. Change Priority
For option 1, element is inserted in one queue as described above.
For option 2, ask for an element and search for it in all three queues. If found, display its queue name otherwise display "Element not found".
For option 3, ask for an clement, if it exists in a queue, ask for its new priority as:
Want to Increase/Decrease its priority (I/D) ? I
And then remove the element from its existing queue and add it to the new queue as changed priority.
You can understand by Watching video :-
Answer =
HighestPr = [ ] NormalPr = [ ] LowestPr = [ ] while True : print() print("Enter your choice as per given -") print("1 = For insert element Enter insert ") print("2 = Search for Element enter search ") print("3 = for change Priority enter change") print("4 = For Exit enter exit ") print() user = input("Enter your choice :- ") if user == "insert" : data = input("Enter element :- ") priority = input("Enter Priority(Highest/ Normal / Lowest (H/N/L): :- ") if priority== "H": HighestPr.append(data) elif priority== "N": NormalPr.append(data) elif priority== "L": LowestPr.append(data) elif user == "search" : data = input("Enter element :- ") if data in HighestPr : print(data,"Present in HighestPr Queue") elif data in NormalPr : print(data,"Present in NormalPr Queue") elif data in LowestPr : print(data,"Present in LowestPr Queue") else: print("Not found !!!!") elif user == "change" : data = input("Enter element :- ") newpri = input(" Want to Increase/Decrease its priority (I/D) ? ") if data in HighestPr : HighestPr.remove(data) if newpri == "D" : NormalPr.append(data) elif data in NormalPr : NormalPr.remove(data) if newpri == "D" : LowestPr.append(data) else : HighestPr.append(data) elif data in LowestPr : LowestPr.remove(data) if newpri == "I" : NormalPr.append(data) else: print("Not found !!!!") else : print("HighestPr Queue :-",HighestPr) print("NormalPr Queue :-",NormalPr) print("LowestPr Queue :-",LowestPr) break
Output :-
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- insert
Enter element :- Path
Enter Priority(Highest/ Normal / Lowest (H/N/L): :- H
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- insert
Enter element :- Walla
Enter Priority(Highest/ Normal / Lowest (H/N/L): :- L
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- insert
Enter element :- Portal
Enter Priority(Highest/ Normal / Lowest (H/N/L): :- N
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- insert
Enter element :- Express
Enter Priority(Highest/ Normal / Lowest (H/N/L): :- L
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- search
Enter element :- Python
Not found !!!!
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- search
Enter element :- Path
Path Present in HighestPr Queue
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- change
Enter element :- Portal
Want to Increase/Decrease its priority (I/D) ? D
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- change
Enter element :- Walla
Want to Increase/Decrease its priority (I/D) ? I
Enter your choice as per given -
1 = For insert element Enter insert
2 = Search for Element enter search
3 = for change Priority enter change
4 = For Exit enter exit
Enter your choice :- exit
HighestPr Queue :-['Path']
NormalPr Queue :-['Walla']
LowestPr Queue :-['Express', 'Portal']
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )