The following is an excerpt from a Java-like pseudo-code class (types have not been fully specified)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <= maxsize ; i++) Line 10 should read: for (i = 0; i < maxsize ; i++) Line 10 should read: for (i = maxsize ; i >= 0; i--) Line 13 should come before line 10 Line 15 should read: arr[++size] = val; 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 <= maxsize ; i++) Line 10 should read: for (i = 0; i < maxsize ; i++) Line 10 should read: for (i = maxsize ; i >= 0; i--) Line 13 should come before line 10 Line 15 should read: arr[++size] = val;
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Financial and Managerial Accounting
ISBN: 978-0538480895
11th Edition
Authors: Jonathan E. Duchac, James M. Reeve, Carl S. Warren
Posted Date:
Students also viewed these programming questions
-
The Medical Assurance Company is investigating the cost of a routine office visit to family-practice physicians in the Rochester, New York, area. The following is a list of 39 family-practice...
-
Based on the following production and sales estimates for March for Lolita Company, determine the number of units expected to be manufactured in March. Estimated inventory (units), March 1 31,000...
-
On December 31, 2019, Metlock Inc. borrowed $3,300,000 at 13% payable annually to finance the construction of a new building. In 2020, the company made the following expenditures related to this...
-
How do a manager's responsibilities for change leadership vary among Lewin's three phases of planned change?
-
Use (a) The Trapezoidal Rule, (b) The Midpoint Rule, (c) Simpsons Rule to approximate the given integral with the specified value of n. (Round your answers to six decimal places.) -. /x3 1 dx, %3 =...
-
Barbara Vigil, Chief Justice, New Mexico Supreme Court Ken Badilla bought a pair of Brahma brand work boots from Wal-Mart on October 19, 2003. The boots packaging had these express descriptions: iron...
-
Alabama Corporation purchases raw materials on account from various suppliers. It normally pays for 70 percent of these in the month purchased, 20 percent in the first month after purchase, and the...
-
Direct labor-hours Machine-hours Total fixed manufacturing overhead cost Variable manufacturing overhead per machine-hour Variable manufacturing overhead per direct labor-hour Required: 1. Compute...
-
At the end of the day the clerk for Wales Variety Shop noticed an error in the amount of cash he should have. Total cash sales from the sales tape were $1,204, whereas the total cash in the register...
-
You are an exercise physiologist at a hospital-based wellness facility. Mr. Martinez recently joins your facility. Mr. Martinez is 50-yr-old male. He does not participate in any exercise programs...
-
Company X is a job-order costing manufacturer that uses a plantwide overhead rate based on direct labor hours. The company's accountant determined that the predetermined overhead rate for this year...
-
Ten years ago, Emma purchased an investment for $22,500. The investment earned 7 percent interest each year. Using the equation method, what is the worth of the investment today??
-
This is my code everything works fine but i want more circles to appear can someone tell me how i can multiply the circles thanks function Circle() { this.name = "circle"; var x = 0; var y = 0; var...
-
What do you think is the purpose of each of the four accounting conventions mentioned, what can be prevented by adhering to these conventions?
-
During the year, Lincoln Corporation had the following business casualty loss: Asset Adjusted basis FMV before the casualty FMV after the casualty Insurance Recovery A $800 $700 $300 $250 What is the...
-
Evaluate the integral du ; u
-
Using the information presented in Problem 13.4B, prepare a partial statement of cash flows for the current year, showing the computation of net cash flows from operating activities using the...
-
On July 1, 2012, Kim Wheeler established an interior decorating business, Aztec Designs. During the month, Kim completed the following transactions related to the business: July 1. Kim transferred...
-
Katula Company reported the following on the company's income statement in 2012 and 2011: a. Determine the number of times interest charges were earned for 2011 and 2012. Round to on decimal place.b....
-
For a major university, match each cost in the following table with the activity base most appropriate to it. An activity base may be used more than once, or not used at all. Cost: Activity Base: 1....
-
From the following trial balance of G. Foot after his first year's trading, you are required to draw up a statement of profit or loss for the year ending 30 June 2016. A statement of financial...
-
At the beginning of the financial year on 1 April 2017, a company had a balance on plant account of 372,000 and on provision for depreciation of plant account of 205,400. The company's policy is to...
-
What circumstances might lead you to write-off a debt as bad and not close the debtor's account?
Study smarter with the SolutionInn App