Skip to content

Instantly share code, notes, and snippets.

@computer-tutor
Created April 25, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save computer-tutor/d513171f15d17636ea08fcfd5769b0c0 to your computer and use it in GitHub Desktop.
Save computer-tutor/d513171f15d17636ea08fcfd5769b0c0 to your computer and use it in GitHub Desktop.
def enqueue(queue,x):
queue.append(x)
def dequeue(queue):
global front #using global variable to modify front
t=queue[front]
front +=1 #Front is incremented, thus there is no shifting
return t
l=[]
front =0
enqueue(l,1)# l=[1]
print(l)
enqueue(l,2)# l=[1,2]
print(l)
enqueue(l,3)# l=[1,2,3]
print(l)
print(dequeue(l))# 1 deleted
print(dequeue(l))# 2 deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment