User Tools

Site Tools


haas:spring2013:common:data-p04-20121107130000

Using a Linked List-Based Stack, implement the following program:

  • Split up the code to have separate functions which do the following:
    • main() - central program, provides a menu to launch into each operation.
    • push() - prompt the user for a value and push it onto the stack
    • pop() - pop the top node off the stack and display it

This is essentially testing your ability to organize code into functions, and to build upon those functions (especially those of your linked list implementation you'll want to use).

Having a menu-driven interface (just text will do), will enable more selective testing of the functionality of your Stack. Note that when the program is run, the menu should be the very first thing the user sees, and no stack should be in existence until (and if) a user decides to do so. The menu should also have some sort of exit option.

Also implement an option where the user can set the size of the stack, so that the user can experience a “stack overflow” message should the limit be reached (be sure to display “stack underflow” messages as appropriate too).

To submit, place any and all related source files in your repository under the following directory: ~/src/data/submit/p04/ (creating any missing directories as needed) and add/commit/push it to your personal repository.

I plan to wander around and check off with each person as part of this project's evaluation, so be prepared to show me your code, perform a sample run, and potentially answer any questions I may have about the code.

Points I will look to evaluate:

  • Is the code well organized, adequately commented, and consistenty indented?
  • Does it compile and run (any combination of actions) without warning, error, or problem?
  • Does it have and use functions for the various stack operations?
  • Do the stack functions adequately make use of the linked list functions?
  • Does the menu allow full and operational and correct control over all actions of the stack?

Potential sample output of this desired program:

lab46:~/src/data/submit/p04$ ./stackprog

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 0

Enter Stack Size (0 for unlimited): 3
Stack Size Set to 3.

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
*STACK UNDERFLOW*

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 1
Enter value to push onto stack: 6
6 has been pushed onto the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 1
Enter value to push onto stack: 5
5 has been pushed onto the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
A 5 has been popped off of the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 1
Enter value to push onto stack: 4
4 has been pushed onto the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 1
Enter value to push onto stack: 2
2 has been pushed onto the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 1
Enter value to push onto stack: 1
*STACK OVERFLOW*

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
A 2 has been popped off of the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
A 4 has been popped off of the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
A 6 has been popped off of the stack

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 2
*STACK UNDERFLOW*

Stack Operations
----------------------
0. Set Size
1. Push
2. Pop
9. Quit

Enter Selection: 9
lab46:~/src/data/submit/p04$ 
haas/spring2013/common/data-p04-20121107130000.txt · Last modified: 2012/10/29 20:47 by 127.0.0.1