Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MoreArrayList
- {
- // Think!
- //
- // What are the repeatable units of work?
- // This is what goes in the for loop.
- //
- // If you see the keyword "every" or "for every X do Y"
- // there's probably a loop involved.
- //
- // What are the subproblems? If X is hard to do,
- // would it be easier if you already have Y? If yes, then
- // solving Y first is a subproblem.
- public void normalize(ArrayList<Integer> input) {
- // Normalize the input:
- // This means scale all the values in the input
- // so that they fit from 0 to 1 (this means dividing
- // each element by the max element).
- }
- public void shuffle(ArrayList<int> numbers) {
- // Rearrange the items in numbers so that they are in a
- // random order.
- }
- public void removeDuplicates(ArrayList<String> words) {
- // Remove all duplicate Strings that appear in |words|.
- // This means that if a word shows up twice, remove
- // the second appearance of that word from |words|. If it
- // shows up more than twice, remove ALL duplicate appearances
- // of that word from |words|.
- //
- // Be careful of going out of bounds!
- }
- public int findLongestIncreasingSequence(ArrayList<int> numbers) {
- // Okay, so first think: How can you break this problem
- // down into easier sub-problems? (Hint: What if you had an
- // ArrayList of ArrayLists....woahhh, so meta).
- }
- // Next question is very very similar to what you did last week!
- private class Item {
- int value;
- int count;
- }
- public ArrayList<Item> buildHistogram(ArrayList<int> numbers) {
- // Build a histogram of how many times a number appears in
- // numbers.
- //
- // For each unique number that appears in numbers,
- // create an "Item" object where |value| is that number and
- // |count| is thenumber of times that number is scene in numbers.
- }
- public ArrayList<Integer> simpleSort(ArrayList<Integer> input)
- {
- // Returns a sorted version of the input.
- // Use the following strategy:
- // Take each int in input one at a time and
- // insert them into a new ArrayList that is
- // originally empty. Every time you add a new
- // int, you add it into the right place so that
- // the new ArrayList remains sorted.
- }
- // Challenge question:
- public void insertionSort(ArrayList<Integer> input)
- {
- // A fancier version of simple sort. Use a SINGLE ArrayList.
- // Destructively modify the ArrayList that was given to you
- // instead of creating a new sorted ArrayList.
- //
- // The solution to this problem is known as insertion sort.
- // (We'll revisit this later in the searching and sorting
- // chapter).
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement