-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
327f808
commit 896d03f
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
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
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") | ||
|
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
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") | ||
|