Created
April 25, 2020 11:16
-
-
Save computer-tutor/9e2e9bdf0b083c188fa5df3f3f13369b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enqueue(queue,x): | |
queue.append(x) | |
def search(a,b,c,x): | |
if x in a: | |
print(x,"is in HighestPr Queue") | |
elif x in b: | |
print(x,"is in NormalPr Queue") | |
elif x in c: | |
print(x,"is in LowestPr Queue") | |
else: | |
print('Not Found') | |
def changePriority(a,b,x): | |
t=len(a) | |
for i in range(t): | |
if a[i]==x: | |
a.pop(i) | |
break | |
enqueue(b,x) | |
HighestPr = [] | |
NormalPr = [] | |
LowestPr = [] | |
loop=1 | |
while loop==1: | |
print("Welcome to Computer Tutor! Your available options are:") | |
print("\n1. Insert Element \n2. Search an element \n3. Change Priority of an element \n4. Exit") | |
o=int(input("\nOption you want to choose: (1/2/3/4):")) | |
if o==1: | |
x=input("\nEnter an element: ") | |
p=input('Priority (H/N/L): ') | |
if p=='H': | |
enqueue(HighestPr, x) | |
elif p=='N': | |
enqueue(NormalPr, x) | |
else: | |
enqueue(LowestPr, x) | |
elif o==2: | |
x=input('Enter element to be searched:') | |
search(HighestPr, NormalPr, LowestPr, x) | |
elif o==3: | |
x=input('Enter element:') | |
c=input("Do you want to increase or decrease the priority? (I/D):") | |
if c=="I": | |
if x in HighestPr: | |
print("Already in Highest Priority") | |
elif x in NormalPr: | |
changePriority(NormalPr, HighestPr, x) | |
elif x in LowestPr: | |
changePriority(LowestPr, NormalPr,x) | |
else: | |
print(x, 'Not found') | |
else: | |
if x in LowestPr: | |
print("Already in Lowest Priority") | |
elif x in NormalPr: | |
changePriority(NormalPr, LowestPr, x) | |
elif x in HighestPr: | |
changePriority(HighestPr, NormalPr,x) | |
else: | |
print(x, 'Not found') | |
else: | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment