Q. Each node of a STACK contains the following information :
(i) Pin code of a city,
(ii) Name of city
Write a program to implement following operations in above stack
(a) PUSH () To push a node in to the stack.
(b) POP( ) To remove a rode from the stack.
You can understand by Watching video :-
stack = [ ] while True : print() print("Enter your choice as per given -") print("1 = For insert data Enter insert ") print("2 = For delete data enter delete ") print("3 = For Exit enter exit ") print() user = input("Enter your choice :- ") if user == "insert" : pin = int(input("Enter the pin code of city :- ")) city = input("Enter name of city :- ") data = [ pin , city ] stack.append(data) elif user == "delete" : if stack == [ ]: print("Under Flow") else : stack.pop() else : break print("Now our stack = ",stack)
Output :-
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- insert
Enter the pin code of city :- 100059
Enter name of city :- Delhi
Now our stack = [[100059, 'Delhi']]
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- insert
Enter the pin code of city :- 000000
Enter name of city :- India
Now our stack = [[100059, 'Delhi'], [0, 'India']]
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- insert
Enter the pin code of city :- 168974
Enter name of city :- Lucknow
Now our stack = [[100059, 'Delhi'], [0, 'India'], [168974, 'Lucknow']]
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- delete
Now our stack = [[100059, 'Delhi'], [0, 'India']]
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- delete
Now our stack = [[100059, 'Delhi']]
Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit enter exit
Enter your choice :- exit
>>>
thank you
ReplyDeletejust the spelling of choice is wrong , but its fine as it does affect the code
Sorry, I will Correct it.
Deletewhy didnt you create pre defined functions for push and pop ?
ReplyDeleteBecause question does not want to make function.
Deletecheck part (a) and (b) stating push() and pop()
ReplyDeleteNot required.
Deletethis means that we have to define the functions right ?
ReplyDeleteNot necessary.
Delete(b) POP( ) To remove a rode from the stack. In that node will come spelling is wrong
ReplyDelete????
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )