Time Left - 15:00 mins

GATE 2024 : Data Structure and Programming Quiz- 3

Attempt now to get your rank among 292 students!

Question 1

The following C function takes a singly–linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1,2,3,4,5,6,7 in the given order. What will be the contents of the list after the function completes execution?

Question 2

Consider the following linked list.

Following operations are performed on this singly linked list:

i) struct node *p;

ii) p = s --> next -->next-->next-->next;

iii) s --> next -->next-->next = p -->next-->next ;

iv) p = s --> next -->next-->next-->next;

v) p --> next = s --> next -->next;

vi) Pf(s --> next -->next-->next --> next -->next-->next --> next -->next-->next--> next -->next-->next-->data)

What will the last statement print?

Question 3

Consider the following C code which is implemented on a linked list :
Struct node *Insert_x_and_y(Struct node *S , int X , int Y)
{
    Struct node *P , *Q , *S1;
    P = (Struct node*)malloc(sizeof(Struct node));
    P->data = x;
    P->next = NULL;
    if(S==null)
    return (NULL);
    if(S->data==y)
   {
      P->next = S;
      S = P;
      return (S);
   }
   else
  {
      S1=S;
           while(S1->data!=y && S1->next!=NULL)
           {
               Q=S1;
               S1=S1->next;
            }
     if(S1->data==y)
    {
        Q->next = P;
        P->next = S; 
    }
  else
       Printf("No y found")
      return (S);
  }
}
What does the following code does ?

Question 4

Consider the following C program.
struct listnode
{
    int data;
    struct listnode *next;
} ;
  void fun (struct listnode *head)
{
   if (head == NULL || head → next ==NULL) return;
   struct listnode ∗tmp = head → next;
   head → next = tmp → next;
   free (tmp);
   fun (head → next);
}
What is the functionality of the above function?

Question 5

Consider a doubly linked list. The doubly linked list contains pointers to next nodes and to previous nodes as well. Hence a node in doubly linked list contains a data and two pointers. Our task is to insert a new node at the second last position of the linked list. Find the number of pointers that needs to be updated in doubly linked list to do so __________.

Question 6

Consider a linked list which has 10 nodes and the nodes have value 1,2,3……10 in this order from head to last. Now this linked list is passed as parameter to the below given code :
 
Now suppose the value of n taken in above code is 4 , then what will be the value printed by above code _____________.
  • 292 attempts
  • 1 upvote
  • 2 comments
Mar 10GATE & PSU CS