Question: The following is an excerpt from a Java-like pseudo-code class (types have not been fully specified) to implement a list ADT using arrays. In

The following is an excerpt from a Java-like pseudo-code class (types have not been fully specified) to 

The following is an excerpt from a Java-like pseudo-code class (types have not been fully specified) to implement a list ADT using arrays. In particular it shows the append method to add a new element onto the end of the underlying array. However there is a logical bug in the code. What is the bug? 01: int size= 0; 02: int maxsize = 16; 03: int[] arr = new int[maxsize]; 04: 05: public void append(val, list) 06: { 07: 08: 09: 10: 11: 12: 13: 14: 15: 16:} if (size = maxsize) { int[] newArr = new int[maxsize 2]; for (i = 0; i < size; i++) newArr[i] = arr[i]; arr = newArr; maxsize = maxsize + 2; * arr[size++] = val; Line 1 should read: private int size = 16; Line 7 should read: if (size > maxsize) Line 10 should read: for (i = 0; i = 0; i--) Line 13 should come before line 10 Line 15 should read: arr[++size] = val;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided pseudocode represents a basic implementation of a list Abstract Data Type ADT using arrays in a Javalike language The excerpt focuses on ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!