Write the pseudo-code (or C++, Java,Python or pseudo-code) to insert the <nunode
ID: 3855062 • Letter: W
Question
Write the pseudo-code (or C++, Java,Python or pseudo-code) to insert the <nunode> at the <head> of the list. After the insertion, the <nunode> will become the <head>:
Class LinkedList<T>
Node<T> head
Node<T> tail
Write the pseudo-code (or C++, Java,Python or pseudo-code) to insert the <nunode> at the <head> of the list. After the insertion, the <nunode> will become the <head>:
Class LinkedList<T>
Node<T> head
Node<T> tail
Class LinkedList<T>
Node<T> head
Node<T> tail
Explanation / Answer
Pseudocode for insertion at head in linked list :
1. Create a nunode of type <T> .
2. if head == NULL
Then head = nunode
3. else
nunode -> next = head
head = nunode.
Pictorial representation of insertion of nunode at head.
Case 1 : if head = NULL
-> it means there is no list found. So nunode is the head .
Above nunode is head node.
Case 2 :
1 . initially head node is head.
2. Now new node nunode is created and ready to insert at head.
3. Operation of inserting at head .I.e nunode -> next = head
4. Changing nunode as head.
5.now nunode is inserted at head.
Data (nunode,head) AddressRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.