5. Stacks

  • Feel free to use your laptop

  • You are strongly encourage to work with others

    • When you get stuck, ask those sitting around you for help

    • Get used to working together in the labs

    • Peer teaching and peer learning has been empirically shown to be very effective

5.1. Playing with Stacks

The goal is to implement an ArrayStack based on the the details discussed in the Stack Topic and the ArrayStack Topic.

5.1.1. Implementing an ArrayStack

  1. Download the Stack interface and add it to the src folder

  2. Create an ArrayStack class for the implementation

  3. Complete the ArrayStack class based on the ArrayStack Topic’s description

    Note

    Obviously one can simply download the ArrayStack code and copy/paste it into the ArrayStack class, but this defeats the purpose of the lab. Instead, slowly and deliberately implement each method and take the time to understand the details.

  4. Add the ArrayStackTest unit tests to the project in a test folder

  5. Run the ArrayStackTest unit tests and ensure all tests pass

5.1.2. Reversing a String

  1. Write a function called reverseString that takes a string and returns the reverse of the original

    • This function must use a stack for the reversing of the string

    • Below is a skeletal method and some simple testing code

    public static void main(String[] args) {
        String alphabet = "abcdefghijklmnopqrstuvwxyz";
        String tebahpla = reverseString(alphabet);
    
        System.out.println(alphabet);
        System.out.println(tebahpla);
    }
    
    public static String reverseString(String originalString) {
        Stack<Character> characterStack = new ArrayStack<>();
        StringBuilder stringBuilder = new StringBuilder();
    
        // Add Code Here
    
        return stringBuilder.toString();
    }
    

5.2. Kattis Problems

  1. https://open.kattis.com/problems/quadrant

  2. https://open.kattis.com/problems/judgingmoose

  3. https://open.kattis.com/problems/timeloop

  4. https://open.kattis.com/problems/oddities

  5. https://open.kattis.com/problems/fizzbuzz

  6. https://open.kattis.com/problems/twostones

  7. https://open.kattis.com/problems/spavanac

  8. https://open.kattis.com/problems/cetvrta

  9. https://open.kattis.com/problems/bus

  10. https://open.kattis.com/problems/timeloop

  11. https://open.kattis.com/problems/oddities

  12. https://open.kattis.com/problems/fizzbuzz

  13. https://open.kattis.com/problems/sibice

  14. https://open.kattis.com/problems/datum

  15. https://open.kattis.com/problems/dicecup

  16. https://open.kattis.com/problems/autori

  17. https://open.kattis.com/problems/apaxiaaans

  18. https://open.kattis.com/problems/hissingmicrophone

  19. https://open.kattis.com/problems/trik

  20. https://open.kattis.com/problems/pot

  21. https://open.kattis.com/problems/filip

  22. https://open.kattis.com/problems/reversebinary

  23. https://open.kattis.com/problems/sevenwonders

  24. https://open.kattis.com/problems/zamka

  25. https://open.kattis.com/problems/bijele

  26. https://open.kattis.com/problems/cold

  27. https://open.kattis.com/problems/nastyhacks

  28. https://open.kattis.com/problems/grassseed

  29. https://open.kattis.com/problems/pet

  30. https://open.kattis.com/problems/batterup

  31. https://open.kattis.com/problems/aboveaverage

  32. https://open.kattis.com/problems/icpcawards

  33. https://open.kattis.com/problems/quickbrownfox

  34. https://open.kattis.com/problems/nodup

  35. https://open.kattis.com/problems/conundrum

  36. https://open.kattis.com/problems/bela

  37. https://open.kattis.com/problems/kornislav