Following the style of the figures in this chapter, draw the list that would fro
ID: 3803201 • Letter: F
Question
Following the style of the figures in this chapter, draw the list that would from each of the following code sequences: a. RefUnsortedList myList = new RefUnsortedList (): nyList.add(5): myList.add(9): myLost.add(3): RefUnsortedList myLost = new RefUnsortedList (): myList.add(5): myList.add(9): myList.add(3): myLost.remove(9): c. RefSortedList myLiset = new RefCJnsortedList (): myList.add(5): myList.add(9): myList.add(3): d. RefSortedList myList = new RefSortedList myList.add(5): myList.add(9): myList.add(3): myList.remove(9):Explanation / Answer
(a) Since RefUnsortedList is a unsorted list, and the order of the elements is not important, add() method can add new elements to the front of the list. Hence, list after the three add operations will be:
3
9
5
(b) After adding three elements in the list:
3
9
5
remove() pass an object argument and if an equivalent element exists on the list, remove one instance of that element from the list. Instance is removed by "jumping over". Hence, after myList.remove(9), the list will be:
3
5
(c) The list is:
3
9
5
(d) The list will be:
3
5