Discover the best answers at Westonci.ca, where experts share their insights and knowledge with you. Get immediate and reliable solutions to your questions from a community of experienced experts on our Q&A platform. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

#7. Linked list - print last node... Extra info/hint? It's free
Given the following class for the nodes in a linked list:
public class Node {
...
public Node getNext() {...} // return next field
public int getData() {...} // returns data
}
Assuming that the variable head points to (i.e. contains the address of) the first node of a linked list, write the
statement(s) to print the data value in the last node of the linked list to the console. The format of the output must be
"Last node has: n" where n is the number.
You may declare additional variables and assume that there is at least one node in the linked list.
Sample console I/O execution sequence
Last node has: 35
Type or paste your response to this question here
#4. Linked list - every other node... Extra info/hint? It's free
I have a program which prompts a user for an integer (n) and then builds a linked list with numbers between 1 and n.
For example, if the user enters 5, the program will build a linked list with 1 through 5, and display it as 5, 4, 3, 2, 1.
I would like to also display every other node data in this program i.e. 5, 3, 1 for the above example.
Given the following class for the nodes in a linked list:
public class Node {
...
public Node getNext() {...} // return next field
public int getData() {...} // returns data
}
Assuming that the variable head points to (i.e. contains the address of) the first node of the linked list, write the
statement(s) to print the data value in every other node of the linked list to the console. For example if the list has 5->4->3->2->1, the output should be 5 3 1 i.e. the numbers only with spaces in-between.
If the list is empty 0 size), you code should not print out anything.
You may declare additional variables and assume that the list may have any number of nodes including zero.
If the list is empty, do not print anything, otherwise print the data separated by white spaces.
Sample console I/O execution sequence
Enter list size: 5
List data: 5 4 3 2 1
Every other data: 5 3 1
Enter list size: 0
List data:
Every other data:
Type or paste your response to this question here
#5. Single linked list - average... Extra info/hint? It's free
For this problem, I have a complete linked list program which supports the following commands from the user:
insert, display, delete, average, find, insertBefore, insertAfter. insert allows them to insert a number into the current list,
display will display the numbers in the current list
etc.
The program is complete except that I have removed the body of the method for averaging the numbers in the linked list..
Given the following class for the nodes in a linked list:
public class Node {
...
public Node getNext() {...} // return next field
public int getData() {...} // returns data
}
Assuming that the variable head points to (i.e. contains the address of) the first node of a linked list, write the
statements to find the average of all data values in the linked list. For example, average() will return something like
"avg: 2.67" or "Empty". The average should be returned as a string with exactly two digits of decimal accuracy, or
Empty if the list is empty. Your statements will be inserted inside a method like the following:
public String average() {
// Whatever statements you provide in response to this question will // be inserted here BY THE SYSTEM and then compiled and tested as part of
// a larger program which does many other things with the linked list
}
Sample console I/O execution sequence
Linked list code sample. Options are:
(insert, display, delete, average, find, insertBefore, insertAfter)
What would you like: insert 4
inserted 4
What would you like: insert 1
inserted 1
What would you like: insert 3
inserted 3
What would you like: average
avg: 2.67
What would you like: delete 3
deleted 3
What would you like: delete 4
deleted 4
What would you like: delete 1
deleted 1
What would you like: average
Empty
What would you like: Exit
Bye

Sagot :

Visit us again for up-to-date and reliable answers. We're always ready to assist you with your informational needs. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.