Documente Academic
Documente Profesional
Documente Cultură
STACK
Register is an entity which can hold a maximum of 100 names. The register enables the user
to add and remove names from the topmost end only.
Specify the class Register giving details of the functions void push(String) and String
pop(). Assume that the other functions have been defined. [ISC 2018]
Sample output:
Enter the number of students:
5
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Shubham
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Sachin
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Dhoni
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Sehwag
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Ganguly
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
Ganguly popped.
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
Sehwag popped.
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
Dhoni popped.
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
Sachin popped.
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
Shubham popped.
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
2
UNDERFLOW
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
3
Stack is empty
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
1
Enter the name to be pushed:
Kohli
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
3
Kohli
Press 1 to Push
Press 2 to Pop
Press 3 to Display
Press 4 to Exit
Enter your choice:
4