Tutorial 4
Tutorial 4
Tutorial 4
1. The following figure depicts the initial configuration of a circular doubly linked list where
the head is pointing to the first node.
What would be the output after executing the following sequence of steps -
i) head->next->next->next = head->prev
ii) head->prev->prev->prev = head->next->next->next->prev
iii) head->next->next->next->prev = head->prev->prev->prev
iv) printf(“%d” , head->prev->prev->prev->data)
2. If a doubly linked list is declared as
then
i) to inserting a node right most
ii) to deleting a node right most
iii) to insert a node in the middle of the list
iv) to deleting a node in the middle of the list
requires how many changes to various next and prev pointers ? Considering the doubly
linked list is not empty and length of more than equal to 2.
3. The following C function inserts a new element after a specific element ( a pointer is
given which points to that specific element after which the new element needs to be
inserted) in a doubly linked list.
void insertAfter(struct Node* previous, int value) { struct Node* element = (struct
Node*)malloc(sizeof(struct Node)); element->data = value; element->next = previous->next;
previous->next = element; element->prev = previous;
if (element->next != NULL){
______blank line________
}
}
Replace the blank line to complete the function ?
4. Write an algorithm for converting infix to prefix. And find what would be the Prefix
notation for the given equation?
K + L - M * N + ( O ^ P ) * W/U/V * T + Q
5. Which of the following is false about a doubly linked list? Justify your answer.
a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list