Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class MoreArrayList
  2. {
  3. // Think!
  4. //
  5. // What are the repeatable units of work?
  6. // This is what goes in the for loop.
  7. //
  8. // If you see the keyword "every" or "for every X do Y"
  9. // there's probably a loop involved.
  10. //
  11. // What are the subproblems? If X is hard to do,
  12. // would it be easier if you already have Y? If yes, then
  13. // solving Y first is a subproblem.
  14.  
  15. public void normalize(ArrayList<Integer> input) {
  16. // Normalize the input:
  17. // This means scale all the values in the input
  18. // so that they fit from 0 to 1 (this means dividing
  19. // each element by the max element).
  20. }
  21.  
  22. public void shuffle(ArrayList<int> numbers) {
  23. // Rearrange the items in numbers so that they are in a
  24. // random order.
  25. }
  26.  
  27. public void removeDuplicates(ArrayList<String> words) {
  28. // Remove all duplicate Strings that appear in |words|.
  29. // This means that if a word shows up twice, remove
  30. // the second appearance of that word from |words|. If it
  31. // shows up more than twice, remove ALL duplicate appearances
  32. // of that word from |words|.
  33. //
  34. // Be careful of going out of bounds!
  35. }
  36.  
  37. public int findLongestIncreasingSequence(ArrayList<int> numbers) {
  38. // Okay, so first think: How can you break this problem
  39. // down into easier sub-problems? (Hint: What if you had an
  40. // ArrayList of ArrayLists....woahhh, so meta).
  41. }
  42.  
  43. // Next question is very very similar to what you did last week!
  44. private class Item {
  45. int value;
  46. int count;
  47. }
  48.  
  49. public ArrayList<Item> buildHistogram(ArrayList<int> numbers) {
  50. // Build a histogram of how many times a number appears in
  51. // numbers.
  52. //
  53. // For each unique number that appears in numbers,
  54. // create an "Item" object where |value| is that number and
  55. // |count| is thenumber of times that number is scene in numbers.
  56. }
  57.  
  58. public ArrayList<Integer> simpleSort(ArrayList<Integer> input)
  59. {
  60. // Returns a sorted version of the input.
  61. // Use the following strategy:
  62. // Take each int in input one at a time and
  63. // insert them into a new ArrayList that is
  64. // originally empty. Every time you add a new
  65. // int, you add it into the right place so that
  66. // the new ArrayList remains sorted.
  67. }
  68.  
  69. // Challenge question:
  70. public void insertionSort(ArrayList<Integer> input)
  71. {
  72. // A fancier version of simple sort. Use a SINGLE ArrayList.
  73. // Destructively modify the ArrayList that was given to you
  74. // instead of creating a new sorted ArrayList.
  75. //
  76. // The solution to this problem is known as insertion sort.
  77. // (We'll revisit this later in the searching and sorting
  78. // chapter).
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement