Skip to content

Commit

Permalink
data structure queue
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed May 10, 2018
1 parent 327f808 commit 896d03f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
34 changes: 34 additions & 0 deletions DataStructure/queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#function to add element at the end of list
def add_element(stack,x):
stack.append(x)
#function to remove last element from list
def delete_element(stack):
n = len(stack)
if(n<=0):
print("Queue empty....Deletion not possible")
else:
del(stack[0])

#function to display stack entry
def display(stack):
if len(stack)<=0:
print("Queue empty...........Nothing to display")
for i in stack:
print(i,end=" ")
#main program starts from here
x=[]
choice=0
while (choice!=4):
print("\n\tQueue menu \n\n\t1. Add Element \n\t2. Delete Element \n\t3. Display \n\t4. Exit")
choice = int(input("\n Enter your choice : "))

if(choice==1):
value = int(input("Enter value : "))
add_element(x,value)
if(choice==2):
delete_element(x)
if(choice==3):
display(x)
if(choice==4):
print("You selected to close this program")

32 changes: 31 additions & 1 deletion DataStructure/stack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
#function to add element at the end of list
def push(stack,x):
stack.append(x)
#function to remove last element from list
def pop(stack):
del(stack[])
n = len(stack)
if(n<=0):
print("Stack empty....Pop not possible")
else:
stack.pop()

#function to display stack entry
def display(stack):
if len(stack)<=0:
print("Stack empty...........Nothing to display")
for i in stack:
print(i,end=" ")
#main program starts from here
x=[]
choice=0
while (choice!=4):
print("\n\t\t\t stack menu \n\t1. push \n\t2. pop \n\t3. Display \n\t4. Exit")
choice = int(input("Enter your choice"))

if(choice==1):
value = int(input("Enter value "))
push(x,value)
if(choice==2):
pop(x)
if(choice==3):
display(x)
if(choice==4):
print("You selected to close this program")

0 comments on commit 896d03f

Please sign in to comment.