Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
The provided pseudocode represents a basic implementation of a list Abstract Data Type ADT using arrays in a Javalike language The excerpt focuses on ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started