by ta a te Gront ade in the linked list is inserted, where would the Null be? (1
ID: 3874106 • Letter: B
Question
by ta a te Gront ade in the linked list is inserted, where would the Null be? (1marks) ) Which function works faster, InsentFront...) or Insertail...? Explain your answer (I marks) dn the uime that initaly the linked lis is empty and we call the following functions on the list pointed to by head: InsertFront (Pressman, 5); InsertFront (William, 22); InsertTail(Dietel, 45); InsertFront (Ivan, 7) InsertTail(Oliva, 6); What will be the output if we call display ) function on this list now? e) In the following implementation of display function.assume link is a class and it has also a display() method public void display link thelink firstlink; while(thelink !=null){ thelink.displayO: System.out.printin"next link: "+thelink next) thelink-thelink.next System.out.printinO: Is there anything wrong in the code? Justify yourExplanation / Answer
b
Once the front node in the linked list is inserted then null would pointing towards same as next node.
Because new node is always added before the head of the given linked list.
c
Insert a node at the head of a linked list is faster
Because we have to just insert a node at front where as in tail we have to check whether list is empty or not first.
Insert a node at the head of a linked list
Node Insert(Node head,int x) {
Node node = new Node();
node.data = x;
node.next = head;
return node;
}
Insert a node at the tail of a linked list
Node Insert(Node head,int data) {
if (head == null){
head = new Node();
head.data = data;
}
else {
Node node = head;
while (node.next != null){
node = node.next;
}
node.next = new Node();
node.next.data = data;
}
return head;
}
d
display method will display the following
ivan, 7 -> William, 22 -> Pressman, 5 -> Dietel 45 -> Oliva , 6 ->
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.