public class DualArrayDequecT extends AbstractListeT ArrayStack front; ArrayStac
ID: 3596350 • Letter: P
Question
public class DualArrayDequecT extends AbstractListeT ArrayStack front; ArrayStackT> back In order to implement get () we need to get it from the ArrayStack, front or back. We can express this as (a) front.get (i) b) front.get (front.size1) (c) back.get (i-front.izeO) Either (b) or (c) depending on the value of i and front.size) (e) Either (a) or (c) depending on the value of i and front.sizeO 20. Recall that a RootishArrayStack stores a list in a sequence of arrays (blocks) of sizes 1, 2, 3,4,... public class RootishArrayStack extends AbstractListExplanation / Answer
19.
Inorder to get a value in the list the
From front it will be peek element index - i -1. This returns the index from front. -1 is used
to get index or else the position is returned
From back it is like i - peek element index which is reverse case of the above one
20.
Here RootishArrayStack is like, if size is 5. it will be like
[0] [1 element]
[1] [2 elements]
[2] [3 element]
[3] [4 elements]
[4] [5 elements]
List<T[]> blocks;
List holds the numbers
T[] represents the datatype and index like 0, 1, 2....
blocks is the name of the RootishArrayStack
21.
If the size of RootishArrayStack is 10 then it will be like
Index No of elements
[0] [1 element]
[1] [2 elements]
[2] [3 element]
[3] [4 elements]
[4] [5 elements]
[5] [6 element]
[6] [7 elements]
[7] [8 element]
[8] [9 elements]
[9] [10 element]
Total no of elements = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
22.
In RootishArrayStack get(13) will be
[0] [1 element]
[1] [2 elements]
[2] [3 element]
[3] [4 elements]
[4] [5 elements]
No of elements upto index 3 = 1 + 2 + 3 + 4 = 10
No of elements upto index 4 = 1 + 2 + 3 + 4 + 5 = 15 > 12 so the get(13) will be in list[4]
[4][1] = 11 th element
[4][2] = 12th element
[4][3] = 13th element
**Comment for any further queries.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.