akosiraff

Download StackQueue

May 7th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/stackqueue/
  3. Creating Stacks and Queues
  4. A stack is a data structure that operates on the LIFO principle (last in, first out). You can think of a stack as a stack of weights where the weight on the bottom was placed there first, but all of the weights on top of it must be removed before it can be moved.
  5. A queue is a data structure that operates on the FIFO principle (first in, first out). You can think of a queue as a checkout line at the store. Shoppers enter the queue at the end of the line and then progress until they are at the beginning of the line, where they then check out and leave the queue.
  6. Create a stack class for integers:
  7. Within the stack class, store up to thirty integers.
  8. Include a push method that adds an integer to the stack.
  9. Include a pop method that removes an integer from the stack.
  10. When an integer is popped, use it’s position in the stack for the next push.
  11. Include an isFull method that checks to see if the stack is full.
  12. Include an isEmpty method that checks to see if the stack is empty.
  13. Include an output method to display the contents of the stack in LIFO order (the last number pushed should be the first number displayed). Include a message with the display stating what is being displayed.
  14. Display the stack on one line with spaces between the numbers.
  15. Create a queue class for integers:
  16. Within the queue class, store up to thirty integers.
  17. Include a push method that adds an integer to the queue.
  18. Include a pop method that removes an integer from the queue.
  19. When an integer is popped, reorder the queue so that the second integer is now the first, etc. and the last used position will be the next one pushed onto.
  20. Include an isFull method that checks to see if the queue is full.
  21. Include an isEmpty method that checks to see if the queue is empty.
  22. Include an output method to display the contents of the queue in FIFO order (the first number pushed should be the first number displayed). Include a message with the display stating what is being displayed. Display the queue on one line with spaces between the numbers.
  23. Create a demo class that contains the main method:
  24. Create a stack object and a queue object.
  25. Inside a loop, create a menu for the user. The choices are:
  26. -1. Add a number to the stack.
  27. -2. Remove a number from the stack.
  28. -3. Display the stack.
  29. -4. Add a number to the queue.
  30. -5. Remove a number from the queue.
  31. -6. Display the queue.
  32. -7. Quit.
  33. If the user chooses options 1 or 4:
  34. -Check to see if the chosen data structure is full. If it is, display a polite message stating so and display the contents of the chosen data structure.
  35. -If it is not full, push a random number between 1 and 100 (use Math.random()) onto the chosen data structure and display the number being pushed and the contents of the chosen data structure.
  36. -Loop back to the menu.
  37. If the user chooses options 2 or 5:
  38. -Check to see if the chosen data structure is empty. If it is, display a polite message stating so.
  39. -If it is not empty, pop a number off of the chosen data structure and display the number being popped and the remaining contents of the chosen data structure.
  40. -Loop back to the menu.
  41. If the user chooses options 3 or 6 then display the contents of the chosen data structure and loop back to the menu.
  42. If the user chooses option 7 then exit the loop.
  43. Download: http://solutionzip.com/downloads/stackqueue/
Add Comment
Please, Sign In to add comment