Given the array-based list (20, 30, 40, 50), what will the new array look like after the following operations?
ArrayListPrepend(list, 10)
ArrayListAppend(list, 25)
ArrayListRemoveAt(list, 3)
ArrayListPrepend(list, 40)
ArrayListRemoveAt(list, 3)
Show your work on your trace file.
Initially, list is -->
20 | 30 | 40 | 50 |
now, ArrayListPrepend(list, 10) will add element 10 at the beginning of the list, so list will be -->
10 | 20 | 30 | 40 | 50 |
now, ArrayListAppend(list, 25) will add 25 at the end of the list -->
10 | 20 | 30 | 40 | 50 | 25 |
ArrayListRemoveAt(list, 3) will remove element from index 3,
indexing starts from 0, so element removed will be 4th element present at index 3, which is 40
so, new list will be -->
10 | 20 | 30 | 50 | 25 |
ArrayListPrepend(list, 40), will now add 40 at the beginning of the list -->
40 | 10 | 20 | 30 | 50 | 25 |
ArrayListRemoveAt(list, 3) will remove element from index 3, which is 30
40 | 10 | 20 | 50 | 25 |
so, new array will look like -> 40,10,20,50,25
Get Answers For Free
Most questions answered within 1 hours.