Question
Could you help me make my merge more efficient? This code in java also provided node class. please show output! class Node{ int data; Node
Could you help me make my merge more efficient? This code in java also provided node class. please show output!
class Node{ int data; Node next; Node(int d){ data = d; next = null; } }
if text is needed
public void merge(LinkedList2 list, LinkedList2 list2) { Node curr = list.head; Node curr2 = list2.head; Node curr3 = head; int data; while(curr != null && curr2 != null) { if(curr.data public void merge(LinkedList2 list, LinkedList2 list2) Node curr list.head Node curr2 list2.head; Node curr3 head; int data; while(curr!null &curr2! null if(curr.data curr2.data) data curr.data; curr = curr, next; else data curr2.data; curr2 curr2.next Node temp new Node(data); f(curr3null)t curr3- temp; head- temp; else curr3.next = temp: curt3 currs.net; while( curr!= null) { Node same if(curr3 == new Node(curr.data); curr3- same head- same else curr3.next- same; curr3curr3.next curr curr. next; while(curr2! null) Node same = new Node(curr2.data); f(curr3null curr3- same head same; else curr3.next- same; curr3curr3.next curr2 curr2.next
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started