Assignment #5 Instructions

  1. Chapter 14 Exercise 1:
    • Write a method called splitStack that accepts a stack of integers as a parameter and rearranges its elements so that all negatives appear on the bottom of the stack and all the nonnegatives appear on the top.
    • If after this method is called you were to pop numbers off the stack, you would first get all the nonnegative numbers and then get all the negative numbers.
    • It does not matter what order the numbers appear in as long as all the negatives appear lower in the stack than all the nonnegatives.
    • For example, if the stack stores [3, -5, 1, 2, -4], an acceptable result from your method could be [-5, -4, 3, 1, 2].
    • Use a single queue as auxiliary storage
  2. Chapter 14 Exercise 7:
    • Write a method called reverseHalf that accepts a queue of integers as a parameter and reverses the order of all the elements in odd-numbered positions (position 1, 3, 5, etc.) assuming that the first value in the queue has position 0.
    • For example, if the queue stores [1, 8, 7, 2, 9, 18, 12, 0], your method should change it to store [1, 0, 7, 18, 9, 2, 12, 8].
    • Notice that numbers in even positions (positions 0, 2, 4, etc.) have not moved. That subsequence of numbers is still (1, 7, 9, 12).
    • But notice that the number in odd positions (positions 1, 3, 5, etc.) are now in reverse order relative to the original. In other words the original subsequence (8, 2, 18, 0) has now become (0, 18, 2, 8).
    • Use a single stack as auxiliary storage.

Submit the assignment 5 source code file to me as usual via DropItToMe

Follow class programming standards and formatting/indentation rules. Make sure you comment your code! In your method headers you must include pre and postconditions.

Assignment Grading

The assignment is worth 35 points.

This is pretty simple...you get 100% if your output exactly matches the expected output...and...0% if it has ANY differences.

Make sure you get all the spelling, capitalization, punctuation, spacing, etc. correct! Hint: copy-n-paste is a wonderful thing! :)