Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6) Draw a picture of memory after these statements: int[ ] m = new int[2]; m[0] = 0; m[1] = 1; int[ ] p =

6) Draw a picture of memory after these statements: int[ ] m = new int[2]; m[0] = 0; m[1] = 1; int[ ] p = m; p[0] = 4; p[0] = 5

7) Consider the method: public static test2(int[ ] b) { b[0]++; } Draw a picture of memory after these statements (also show what is printed out) int[ ] x = new int[100]; x[0] = 2; test2(x); System.out.println(x[0]);

8) Describe (in English) the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.

9) Write out the following method as a static method for the IntNode class (similar to the book: use data & link) public static int count10s (IntNode head) // Precondition: Head is a reference to a linked list of integers, // condition of the list is unknown (empty or not) // Postcondition: Method returns number of 10s found in the linked list. // list is unchanged.

10) Write out the following method as a static method for the IntNode class (similar to the book: use data & link) public static void insertAtTail (IntNode head, int value) // Precondition: Head is a reference to a linked list of integers, // condition of the list is unknown (empty or not), int refers to value to be // added to the list at the END. // Postcondition: List will have an additional node with the value placed in // it. [Note] break this into two parts finding the right spot and then inserting. The insert you already described up above you just need to look for the last node; that nodes link can be looked at as the head to your new node. Dont forget to watch for empty case.

11) The following is a code fragment used to count the # of occurrences of a specific target integer in an array. int i; int answer = 0; for (i = 0; i < data.length; i++) if (data[i] == target) answer++; Answer of course is the # of times the target is found in the array. Rewrite the code so that it works correctly when the data array is an array of objects and target is a non-null reference to an object with an equals method.

12) Suppose that the variable head is a reference to the head node of a linked list of objects. Each node has an instance variable called link (which is a reference to the next node) and another instance variable called data (which is an Object that's stored in the node). Write a few lines of code to count the number of occurrences of a specific non-null target Object on the list. At the end of your code, a variable called answer should indicate how many times the target appears in the array. Use target.equals to test for equality.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

=+c. What is the GDP deflator for each of these years?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago