ISRO | ISRO CS 2013 | Question 4
The following steps in a linked list
p = getnode() info (p) = 10 next (p) = list list = p
result in which type of operation?
pop operation in stack
removal of a node
inserting a node at beginning
modifying an existing node
The given steps result in the insertion of a new node at the beginning of a linked list.
The first step p = getnode() creates a new node p using the getnode() function (assuming it is defined elsewhere).
The second step info (p) = 10 sets the info field of the new node p to the value 10.
The third step next (p) = list sets the next field of the new node p to the current head of the linked list, which is pointed to by the list pointer.
Finally, the fourth step list = p updates the list pointer to point to the newly inserted node p, effectively making it the new head of the linked list.
Therefore, this sequence of steps performs an insertion operation at the beginning of the linked list, also known as a push operation.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Please Login to comment...