1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Shalnov [3]
3 years ago
12

Write the code necessary to convert the following sequence of ListNode objects: list -> [1] -> [2] / Into this sequence of

ListNode objects: list -> [1] -> [2] -> [3] / Assume that you are using ListNode class as defined in the textbook: public class ListNode { public int data; // data stored in this node public ListNode next; // a link to the next node in the list public ListNode() { ... } public ListNode(int data) { ... } public ListNode(int data, ListNode next) { ... } }
Computers and Technology
1 answer:
dimulka [17.4K]3 years ago
4 0

Answer:

Following are the question in the Java Programming Language:

public class ListNode // define the class which is already mentioned in the question  

{

public int data; //set integer type variable

public ListNode next; //create a next node of the ListNode type

//define constructor for the node with 0 and null

public ListNode()

{

this(0,null); //point to the node with 0 and null

}

//define parameterized constructor with 0 and null

public ListNode(int data)

{

//point to the node with 0 and null

this(data, null);

}

//define parameterized constructor with given data and link

public ListNode(int data, ListNode next) {

//this pointer to point  tthe current data

this.data=data;

//this pointer to point next node

this.next=next;

}

//conversion of the string  

public String toString()

{

//set string type variable

String str = "list->" + this.data;

//at next node

ListNode listNode = this.next;

//set do-while loop

do

{

//print symbol with data

str += "->" +"["+listNode.data+"]";

//point to the next node

listNode = listNode.next;

} while (listNode != null); // iterating the do while loop

//return the string variable str

return str;

}

public static void main(String[] args)// main function

{

//call and pass value to the constructor

ListNode list3 = new ListNode(3);

//call and pass value to the constructor

ListNode list2 = new ListNode(2, list3);

//call and pass value to the constructor

ListNode list1 = new ListNode(1, list2);

//print list variable.

System.out.println(list1);

}

}

<u>Output:</u>

list->1->2->3

Explanation:

<u>Following are the description of the program.</u>

In the following Java Program, we define a class "ListNode" and inside the class.

  • Define non-parameterized constructor that points to the node with 0 and null.
  • Define parameterized constructor that points to the node with 0 and null.
  • Define parameterized constructor that points given data and link .

Finally, we define the main function that passes the value and calls the following constructor.

You might be interested in
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
MAXImum [283]

Answer:

thats what i was about to ask. im not sure

Explanation:

sorry   '-'

3 0
3 years ago
Why is outfitting a workplace with video games in a technology development company consiered a strategic use of money
Jlenok [28]

video games help with hand-eye-coordination and they help with your strategic abilities

3 0
4 years ago
To rename a worksheet, you change the text on the ? HELP ASAP
prohojiy [21]
If this is Excel, it would be C. Sheet tab
5 0
3 years ago
A(n) _____ is a flexible tool used to analyze data using reports that do not have a predetermined format.
Mandarinka [93]

Answer:

decision support system

Explanation:

4 0
3 years ago
a student writes a prgroma to find the factorial of a number. the factorial for a number n is defined as the product of all whol
STALIN [3.7K]

Answer:

B. Integers may be constrained in the maximum and minimum values that can be represented in a program because of storage limitations.

Explanation:

Since the program has been written correctly by the student and yet the output of the program is not what was expected, then the next possibility is that because of the limitations in storage, the integers may be constrained in the minimum and maximum values capable of being represented when writing a program.

7 0
3 years ago
Other questions:
  • Show the contents of a queue after the following operations are performed. Assume the queue is initially empty. enqueue(45); enq
    6·1 answer
  • Francis works in the human resources division of a large oil and gas company in Texas. Francis' tasks include maintaining payrol
    14·1 answer
  • What is the maximum data transfer rate of an ieee 1394a device?
    5·1 answer
  • How can you ensure that your web pages are compliant with a w3c standard?
    9·1 answer
  • ____ is a real-time Internet communications service that notifies users when one or more people are online and then allows them
    10·1 answer
  • I need help with getting a profile pic
    5·1 answer
  • 2. Write a Python regular expression to replace all white space with # in given string “Python is very simple programming langua
    14·1 answer
  • A program that will accept the ages of girls and boys and calculate the total and average age​
    15·1 answer
  • Which action is applicable only to tables?
    13·1 answer
  • Write a statement that takes a variable named file_object that contains a file object and reads its contents into a Python list
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!