Explanation of Solution
Method definition for “reverse()”:
The method definition for “reverse()” is given below:
/* Method definition for "reverse()" */
public void reverse()
{
//Create a list "rev_list" and set it to "null"
Node rev_list = null;
/* This loop will perform up to the first node equals to "null" */
while (first != null)
{
/* Move a node to rev_list from what leftovers of the original list */
/* Set a reference "ref" to first node */
Node ref = first;
/* Set "first" to next first node */
first = first.next;
/* Set next node to "rev_list" */
ref.next = rev_list;
/* Set the "rev_list" to reference "ref" */
rev_list = ref;
}
/* Make the list "rev_list" as the new list */
first = rev_list;
}
Explanation:
From the above method definition,
- Create a list “rev_list” and then set it to “null”.
- Performs “while” loop. This loop will perform up to the first node becomes “null”.
- Set a reference “ref” to first node.
- Set “first” to next value of “first”.
- Assign next node to “rev_list”.
- Assign the “rev_list” to reference “ref”.
- Finally make the list “rev_list” as new list.
Complete code:
The complete executable code for “reverse()” method is given below:
//Define "LinkedList1" class
class LinkedList1
{
/* The code for this part is same as the textbook of "LinkedList1" class */
/* Method definition for "reverse()"*/
public void reverse()
{
//Create a list "rev_list" and set it to "null"
Node rev_list = null;
/* This loop will perform up to the first node equals to "null" */
while (first != null)
{
/* Move a node to rev_list from what remains of the original list */
/* Set a reference "ref" to first node */
Node ref = first;
/* Set "first" to next first node */
first = first...
Want to see the full answer?
Check out a sample textbook solutionChapter 19 Solutions
EBK STARTING OUT W/JAVA:...DATA...
- Why investing in skills and technology is a critical factor in the financial management aspect of system projects.arrow_forwardwhy investing in skills and technology is a critical factor in the financial management aspect of systems projects.arrow_forwardWhy are requirements changing a significant source of risks in system projects?arrow_forward
- I need helpt o resolve the following issuearrow_forwardI would like to know a brief explanation of basic project management concepts.arrow_forwardEX:[AE00]=fa50h number of ones =1111 1010 0101 0000 Physical address=4AE00h=4000h*10h+AE00h Mov ax,4000 Mov ds,ax; DS=4000h mov ds,4000 X Mov ax,[AE00] ; ax=[ae00]=FA50h Mov cx,10; 16 bit in decimal Mov bl,0 *: Ror ax,1 Jnc ** Inc bl **:Dec cx Jnz * ;LSB⇒CF Cf=1 ; it jump when CF=0, will not jump when CF=1 HW1: rewrite the above example use another wayarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,