ISRO | ISRO CS 2018 | Question 34
Consider a singly linked list of the form where F is a pointer to the first element in the linked list and L is the pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
Delete the last element of the list
Delete the first element of the list
Add an element after the last element of the list
Interchange the first two elements of the list
Answer: (A) Explanation:
Interchange the first two elements of the list: To interchange the first two elements of the list, we can simply update the head pointer of the list to point to the second element and update the next pointer of the second element to point to the first element. This can be done in constant time, regardless of the length of the list.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Share your thoughts in the comments
Please Login to comment...