Question: What the following function is doing, can you improve its performance, that is, make it faster, how ? (2 marks) public void MyFun() { while(head!=null)

  1. What the following function is doing, can you improve its performance, that is, make it faster, how ?

(2 marks)

public void MyFun()

{

while(head!=null)

head = head.next;

}

  1. The following function creates a copy of a linked list. Do you see any problems, if yes, fix them. (4 marks)

public LinkedList Copy() //this function is called from main like this:

{ //LinkedList another = mylist.Copy();

LinkedList output = new LinkedList();

while(head != null)

{

output.AddHead(head.value);

head = head.next; }

return output;

}

  1. What will be the output if we call the following function MyFun on the given linked lists. (4 marks)
  1. head->2-1->3->9->5->3->7->4->null
  2. head->1->2->3->4->5->6->7->null

public void MyFun()

{

Node h = head;

while(h != null)

{

System.out.print(h.value+->);

h = h.next.next;

}

}

  1. Write a member function without calling any other function that deletes every alternating node from a given linked list. (5 marks)

So lets say if the input linked list is: head->2->6->1->9->3->4->8->7->null

Then calling your function will yield: head->6->9->4->7->null

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!