Mid 2021-2022
Mid 2021-2022
Page 1 of 2
a) Only in forward b) Only in reverse c) In both directions d) None of them
direction direction
9. What does the following function do for a given Linked List with first node as start?
a) Prints odd nodes of Linked List b) Prints nodes of Linked List in reverse order
c) Prints even nodes of Linked List d) Prints nodes of Linked List without reversing.
10. Suppose cursor refers to a node in a linked list (using the node class with instance variables called
data and link). What Boolean expression will be true when cursor refers to the tail node of the
list?
a) (cursor == NULL) b) (cursor->data == NULL)
c) (cursor->link == NULL) d) None of them
Question 2: Use list and node classes to answer the following question. [15 Marks]
a- What is the output of the following functions if they are members of the list class?
1. void fun1( )
{ node*p,*q;
if(head==NULL) cout<<"list empty.";
if(head->next==NULL) cout<<"still as before.";
else { p=head;
while(p->next!=NULL) { q=p; p=p->next; }
p->next=head; q->next=NULL; head=p; } }
2. void fun2( ) {
node* prev = NULL; node* current = head; node* next;
while (current != NULL)
{ next = current->next; current->next = prev; prev = current; current = next; }
head=prev; }
b- Using node and circularList classes, write a function void modifyNode (int n , int val) which
is used to modify the data of the node at position n in a circular list to be val.
c- Using node and doublyList classes, write a function void printOddInReverse ( ) which is
used to print odd nodes of a doubly linked list in reverse order.
Page 2 of 2