Exercise: Question1 The specifications of the ADT list do not mention the case i
ID: 3820895 • Letter: E
Question
Exercise:
Question1 The specifications of the ADT list do not mention the case in which two or more items have the same value. Are these specifications sufficient to cover this case, or must they be revised?
Question2 Write a pseudocode function swap(aList, i, j) that interchanges the items currently in positions i and j of a list. Define the function in terms of the ADT list operations, so that it is independent of any particular implementation of the list. Assume that the list, in fact, has items at positions i and j. What impact does this assumption have on your solution?
Question 3 What grocery list results from the following sequence of ADT list operations?
aList = a new empty list aList.insert(1, "butter") aList.insert(1, "eggs") aList.insert(1, "milk")
Question 4 Suppose that myList is a list that contains the five objects a b c d e.
a. What does myList contain after executing myList.insert(5, w)?
b. Starting with the original five entries, what does myList contain after executing myList.insert(6, w)?
c. Which, if any, of the operations in parts a and b of this question require entries in the list to shift positions?
Explanation / Answer
Q1 these specifications must be revised.
since it must be defined that waht happens if one insert multiple values at one particular location
eg one cannot determine the output of the follwoign code
list.add(1,abc)
list.add(1,def)
Q2 swap(aList, i, k)
int temp = alist.get(i)
int a = alist.get(k)
alist.set(i,a)
alist.set(k,temp)
Q3 the answer will be i,milk
Q4
a) so the value e at 5 place will be changed to w
and the final output will be a b c d w
b) a b c d e w
c) no entries in the list required shift operations
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.