Knowledge check.

- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.

Question Number 1

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[m];
            j++;
        }
        else
        {
            temp[i]=arr[j];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 2

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        queue[front]=rear;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 3

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 4

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=NULL;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 5

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMin(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 6

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else if(data == node->data)
    {
        return FindElement(node->right,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 7

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 8

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=StackTop;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 9

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct hash *)malloc(sizeof(struct hash));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 10

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)%2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 11

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[j]=temp;
                arry[i]=arry[j];

            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 12

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        if (SortArray[j] > SortArray[j + 1])
        {
            Temp = SortArray[j];
            SortArray[j] = SortArray[j + 1];
            SortArray[j + 1] = Temp;
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 13

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop->next=NULL;
        StackTop=temp;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 14

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    if(arr[j]< =arr[m])
    {
        temp[i]=arr[j];
        j++;
    }
    else
    {
        temp[i]=arr[m];
        m++;
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 15

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                arry[temp]=arry[j+1];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 16

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                SortArray[j] = SortArray[j + 1];
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 17

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        StackTop=temp;
        temp->next=StackTop;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 18

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
        Split(arr,min,mid);

    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 19

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        MergeLists(arr,min/2,mid+1,max/2);
        Split(arr,min,mid);
        Split(arr,mid+1,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 20

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 21

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 22

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 0
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front++];
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 23

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==front)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 24

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data < (node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 25

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[tmp+1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 26

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first > last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 27

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }
    else if(data == (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 28

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 29

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,max);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 30

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(stack[ARRAY_SIZE]==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 31

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE];
int rear=front=ARRAY_SIZE;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 32

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    printf("%d ",node->data);
}

Question Number 33

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 34

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==queue[front])
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 35

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        HeapArry[1]=HeapArry[size];
        tmp=HeapArry[1];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 36

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {



        temp = FindMin(node->right);
        node -> data = temp->data;
        node -> right = DeleteNode(node->right,temp->data);

        temp = node;
        if(node->left == NULL)
            node = node->right;
        else if(node->right == NULL)
            node = node->left;
        free(temp);

    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 37

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 38

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    stack[++StackTop]=ARRAY_SIZE;
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 39

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        temp->next=rear->next;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 40

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[low])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 41

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex] = newnode->next;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 42

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 43

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            hashTable[hashIndex].head = myNode->next;
            temp->next = myNode->next;
            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 44

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value != SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 45

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    temp->next=StackTop;
    StackTop=temp;
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 46

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
    }
    HeapArry[j/2]=tmp;
}

Question Number 47

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE - 1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop-1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 48

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 49

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j==size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 50

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        front=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 51

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 52

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
    }
    HeapArry[j/2]=tmp;
}

Question Number 53

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[j+1]=arr[max];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 54

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 55

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 56

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        return node;
    }

    node->left = InsertNode(node->left,data);
}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 57

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=temp;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 58

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 59

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 60

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            arry[i+1]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 61

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) - 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 62

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        if (value <  SortArray[mid])
        {
            mid = (low + high) / 2;
            high = mid - 1;
        }
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 63

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->left = InsertNode(node->left,data);
    }
    else if(data <  (node->data))
    {
        node->right = InsertNode(node->right,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 64

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=TopValue-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 65

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 66

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }

    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 67

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 68

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==input)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 69

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]||i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 70

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 71

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    value=queue[front];
    front=front+1;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }

    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 72

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 73

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(StackTop!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 74

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be reordered to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    myNode = hashTable[hashIndex].head;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 75

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=mid; k< =j; k++)
        {
            temp[j]=arr[k];
            k++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 76

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 77

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 78

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                SortArray[i+1]  = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 79

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    rear=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 80

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 81

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 82

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=StackTop->data;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop->next;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 83

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 84

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    front=front+1;
    value=queue[front];
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 85

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[j+1];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 86

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=rear;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 87

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 88

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 89

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 90

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode->next = hashTable[hashIndex].head->next;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 91

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 92

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[i] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 93

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=NULL;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 94

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    StackTop=temp;
    StackTop->next=NULL;
    temp->next=StackTop;
    StackTop=temp;

}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 95

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 96

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be added to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    stack[++StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 97

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[temp]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 98

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==0)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 99

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 100

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 101

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    ARRAY_SIZE =StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 102

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {

        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        TopVal=TopVal->next;
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 103

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 104

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid * 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 105

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {


            Temp = SortArray[j];
            SortArray[j] = SortArray[j + 1];
            SortArray[j + 1] = Temp;

        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 106

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be reordered to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            temp = myNode;
            myNode = myNode->next;

            free(myNode);
            break;
        }
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 107

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    {
        printf("Value is found \n");
    }
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 108

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->left, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 109

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be reordered to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    struct node *newnode =  CreateNode(key, name, mark);
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 110

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    front = front->next;
    input=temp->Data;
    free(temp);
    return input;


}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 111

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 112

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else if(arr[j]!=arr[m])
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 113

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[temp+1];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 114

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(front->next!=NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 115

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==node->left)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 116

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j+1];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 117

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->right);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 118

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->next;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 119

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 120

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=front->next;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 121

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 122

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = temp->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 123

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 124

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 125

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 126

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
    {
        node=node->left;
        return FindMin(node->left);
    }
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 127

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[i]===arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 128

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 129

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node);
    printf("%d ",node->data);
}

Question Number 130

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            low = mid + 1;
        else if (value > SortArray[mid])
            high = mid - 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 131

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 132

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            low = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 133

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 134

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[max]=arr[mid+1];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 135

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    stack[StackTop++]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 136

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i!=1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 137

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid - 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 138

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        Temp = SortArray[j];
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 139

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        temp=temp->next;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 140

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = NULL;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 141

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {

        rear=front+1;
        printf("%d ",queue[i]);
    }
}

Question Number 142

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 143

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered and corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    front=rear+1;
    value=queue[front];
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 144

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        node=node->left;
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 145

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 146

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 147

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }
    else if(data != (node->data))
    {
        node->left = InsertNode(node,data);
    }


    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 148

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);

        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 149

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=rear;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=rear;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 150

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=Stack->next;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 151

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[0].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 152

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 153

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp->data=input;
    temp=(struct Node *)malloc(sizeof(struct Node));
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 154

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            if(first==last)
            {
                while(arry[i]< =arry[pivot]&&i< last)
                    i++;
                while(arry[j]>arry[pivot])
                    j--;
                if(i< j)
                {
                    temp=arry[i];
                    arry[i]=arry[j];
                    arry[j]=temp;
                }
            }
            temp=arry[pivot];
            arry[pivot]=arry[j];
            arry[j]=temp;
            QuickSort(arry,first,j-1);
            QuickSort(arry,j+1,last);

        }
    }
}

Question Number 155

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear->next=NULL;
        rear=temp;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 156

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    StackTop = ARRAY_SIZE;
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 157

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]!=HeapArry[j+1]))
            size++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 158

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[temp];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 159

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node ->left = FindMax(node);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 160

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 161

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    stack[StackTop--]=ARRAY_SIZE;
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 162

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 163

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data == node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 164

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=rear;
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 165

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 166

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j==size)||(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 167

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        MergeLists(arr,min,mid,max);
        Split(arr,mid+1,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 168

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j!=size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 169

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        front->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 170

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 171

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 172

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed and reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        rear=rear+1;
        front=rear+1;
        queue[rear]=input;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 173

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node == NULL)
                node = node->left;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 174

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE];
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 175

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{

    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    StackTop = ARRAY_SIZE;
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 176

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 177

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop =StackTop +1;
    stack[StackTop]=input;
}

int Pop(int input)
{
    int TopValue;
    if(stack[StackTop]==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop = StackTop -1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 178

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 179

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[m];
            m++;
        }
        else
        {
            temp[i]=arr[j];
            j++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 180

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push();
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push()
{
    if(StackTop==ARRAY_SIZE - 1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop + 1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop - 1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 181

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    rear=rear+1;
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 182

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 183

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return node;
    }
    else
    {
        return FindElement(node->left,data);
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 184

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        {
            temp[i]=arr[j];
            j++;
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 185

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            temp->next = myNode->next;
            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 186

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    queue[rear]=input;
    rear=rear+1;
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }

}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 187

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=Node->next;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 188

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 189

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        size=HeapArry[tmp];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 190

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 191

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->left == NULL)
                node=temp->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 192

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>size)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 193

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value == SortArray[mid])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value <  SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 194

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[low])
            high = mid - 1;
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 195

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            while(arry[j]==arry[pivot])
                i--;

            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 196

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 197

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 198

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==TopVal)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 199

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
        {
            high = mid - 1;
            low = mid - 1;
        }
        else if (value > SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 200

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = newnode->key;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 201

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode->next;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 202

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 203

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE - 1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop + 1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop== ARRAY_SIZE - 1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue = stack[StackTop];
    StackTop=StackTop - 1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 204

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 205

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
        mid=(min+max)/2;
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 206

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered and corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        rear=front+1;
        queue[front]=input;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 207

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->right = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 208

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        return node;
    else
        FindMax(node->right);
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 209

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    stack[StackTop]=input;
    StackTop=StackTop+1;

}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    StackTop=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 210

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 211

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==node->right)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 212

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        temp->next=front;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 213

The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);

void main()
{
    int SortArray[10];
    int i, j, NumOfValues, Temp, value;

    printf("Enter the number of values to be sorted : \n");
    scanf("%d", &NumOfValues);
    printf("Enter the values :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        scanf("%d", &SortArray[i]);
    }
    printf("Entered values are :  \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    BubbleSort(SortArray,NumOfValues);

    printf("Sorted list : \n");
    for (i = 0; i <  NumOfValues; i++)
    {
        printf("%d\n", SortArray[i]);
    }

    printf("Enter value to be searched :  \n");
    scanf("%d", &value);

    BinarySearch(SortArray,NumOfValues,value);
}

void BubbleSort(int *SortArray,int NumOfValues)
{
    int i,j,Temp;
    for (i = 0; i <  NumOfValues; i++)
    {
        for (j = 0; j <  (NumOfValues - i - 1); j++)
        {
            if (SortArray[j] > SortArray[j + 1])
            {
                Temp = SortArray[j];
                SortArray[j] = SortArray[j + 1];
                SortArray[j + 1] = Temp;
            }
        }
    }
}

void BinarySearch(int *SortArray,int NumOfValues,int value)
{
    int mid,high,low;
    low = 1;
    high = NumOfValues;
    do
    {
        mid = (low + high) / 2;
        if (value <  SortArray[mid])
            high = mid - 1;
        else if (value != SortArray[mid])
            low = mid + 1;
    }
    while (value != SortArray[mid] && low < = high);
    if (value == SortArray[mid])
    {
        printf("Value is found \n");
    }
    else
    {
        printf("Value is not present in the list \n");
    }
}

Question Number 214

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 215

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->left,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 216

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return queue[front];
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 217

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[pivot+1]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 218

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=min; k< =max; k++)
        {
            temp[j]=arr[k];
            j++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 219

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]< arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 220

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 221

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 222

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]==arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 223

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop=StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[--StackTop];
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 224

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = key;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 225

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]!=arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 226

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 227

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=NULL;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 228

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        front=rear;
        rear->next=NULL;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 229

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i > j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 230

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->left);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 231

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=mid; k< =max; k++)
        {
            temp[j]=arr[mid+1];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 232

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    queue[rear]=input;
    rear=rear+1;
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 233

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return node;
    else
        return FindMin(node->left);
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 234

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    rear->next=temp;
    rear=temp;
    rear->next=NULL;

}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(temp!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 235

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        Split(arr,mid+1,max);
        MergeLists(arr,min,mid,max);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]==arr[m])
        {
            temp[i]=arr[j];
            j++;
        }
        else
        {
            temp[i]=arr[m];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 236

The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
    int arr[30];
    int i,size;
    printf("Enter number of elements : \n");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=0; i< size; i++)
    {
        scanf("%d",&arr[i]);
    }
    Split(arr,0,size-1);
    printf("\nSorted list : ");
    for(i=0; i< size; i++)
        printf("%d ",arr[i]);
    getch();
    return 0;
}


void Split(int *arr,int min,int max)
{
    int mid;
    if(min< max)
    {
        mid=(min+max)/2;
        Split(arr,min,mid);
        MergeLists(arr,min,mid,max);
        Split(arr,mid+1,mid+2);
    }
}


void MergeLists(int *arr,int min,int mid,int max)
{
    int temp[30];
    int i,j,k,m;
    j=min;
    m=mid+1;
    for(i=min; j< =mid && m< =max ; i++)
    {
        if(arr[j]< =arr[m])
        {
            temp[i]=arr[m];
            m++;
        }
        else
        {
            temp[i]=arr[j];
            m++;
        }
    }
    if(j>mid)
    {
        for(k=m; k< =max; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    else
    {
        for(k=j; k< =mid; k++)
        {
            temp[i]=arr[k];
            i++;
        }
    }
    for(k=min; k< =max; k++)
        arr[k]=temp[k];
}

Question Number 237

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        arry[pivot]=arry[j];
        arry[j]=temp;
        temp=arry[pivot];
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 238

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int Data;
    struct Node* next;
}*rear, *front;

void Enqueue(int);
int Dequeue();
void Display();

int main()
{
    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();
}

void Enqueue(int value)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->Data=value;
    if (rear == NULL)
    {
        rear=temp;
        rear->next=NULL;
        front=rear;
    }
    else
    {
        rear->next=temp;
        rear=temp;
        rear->next=NULL;
    }
}

int Dequeue()
{
    struct Node *temp=front;
    int input;
    if(temp==NULL)
    {
        printf("\nQueue is empty");
        return 0;
    }
    else
    {
        front = front->next;
        input=temp->Data;
        free(temp);
        return input;
    }

}

void Display()
{
    struct Node *temp=front;
    if(temp!=NULL)
    {
        printf("\nElements are :  ");
        while(rear->next!=NULL)
        {
            printf("\t%d",temp->Data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nQueue is Empty");
}

Question Number 239

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    printf("%d ",node->data);
    PrintPreorder(node);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 240

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE   10
int stack[ARRAY_SIZE];
int StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    if(StackTop==ARRAY_SIZE-1)
    {
        printf("Stack overflow");
        return;
    }
    StackTop =StackTop+1;
    stack[StackTop]=input;
}

int Pop()
{
    int TopValue;
    if(StackTop==-1)
    {
        printf("Stack is empty");
        return -1;
    }
    TopValue=stack[StackTop];
    ARRAY_SIZE=StackTop-1;
    return TopValue;
}

void Display()
{
    int i;
    printf("\nStack Elements:");
    for(i=0; i< =StackTop; i++)
    {
        printf("%d  ",stack[i]);
    }
}

Question Number 241

The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
    int data;
    struct Node *left;
    struct Node *right;

} Node;

Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);

void main()
{

    Node *root = NULL;
    Node * temp;
    root=InsertNode(root, 40);
    root=InsertNode(root, 10);
    root=InsertNode(root, 20);
    root=InsertNode(root, 35);
    root=InsertNode(root, 50);
    root=InsertNode(root, 80);

    root=DeleteNode(root, 50);
    temp=FindElement(root, 80);
    if(temp==NULL)
    {
        printf("Element not found\n");
    }
    else
    {
        printf("Element Found\n");
    }
    PrintInorder(root);
    PrintPreorder(root);
    PrintPostorder(root);

}

Node* FindMin(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->left)
        return FindMin(node->left);
    else
        return node;
}
Node* FindMax(Node *node)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(node->right)
        FindMax(node->right);
    else
        return node;
}

Node * InsertNode(Node *node,int data)
{
    if(node==NULL)
    {
        Node *temp;
        temp = (Node *)malloc(sizeof(Node));
        temp -> data = data;
        temp -> left = temp -> right = NULL;
        return temp;
    }

    if(data >(node->data))
    {
        node->right = InsertNode(node->right,data);
    }
    else if(data <  (node->data))
    {
        node->left = InsertNode(node->left,data);
    }

    return node;

}

Node * DeleteNode(Node *node, int data)
{
    Node *temp;
    if(node==NULL)
    {
        printf("Element Not Found");
    }
    else if(data <  node->data)
    {
        node->left = DeleteNode(node->left, data);
    }
    else if(data > node->data)
    {
        node->right = DeleteNode(node->right, data);
    }
    else
    {

        if(node->right && node->left)
        {

            temp = FindMin(node->right);
            node -> data = temp->data;
            node -> right = DeleteNode(node->right,temp->data);
        }
        else
        {

            temp = node;
            if(node->left == NULL)
                node = node->right;
            else if(node->right == NULL)
                node = node->left;
            free(temp);
        }
    }
    return node;

}

Node * FindElement(Node *node, int data)
{
    if(node==NULL)
    {
        return NULL;
    }
    if(data > node->data)
    {
        return FindElement(node->right,data);
    }
    else if(data <  node->data)
    {
        return FindElement(node->left,data);
    }
    else
    {
        return node;
    }
}

void PrintInorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintInorder(node->left);
    printf("%d ",node->data);
    PrintInorder(node->right);
}

void PrintPreorder(Node *node)
{
    printf("%d ",node->data);
    PrintPreorder(node->left);
    PrintPreorder(node->right);
}

void PrintPostorder(Node *node)
{
    if(node==NULL)
    {
        return;
    }
    PrintPostorder(node->left);
    PrintPostorder(node->right);
    printf("%d ",node->data);
}

Question Number 242

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[size/2]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 243

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[size/2];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[j];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 244

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]==arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 245

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                arry[i]=arry[j];
                arry[j]=temp;
                temp=arry[i];
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 246

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
                arry[i+1]=arry[j];
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 247

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first< last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[j]=temp;
        arry[pivot]=arry[j];
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 248

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = StackTop->next;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=StackTop;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 249

The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);

int main()
{
    int arry[20],size,i;

    printf("Enter size of the array: ");
    scanf("%d",&size);

    printf("Enter elements: ",size);
    for(i=0; i< size; i++)
        scanf("%d",&arry[i]);

    QuickSort(arry,0,size-1);

    printf("Sorted list: ");
    for(i=0; i< size; i++)
        printf(" %d",arry[i]);
}

void QuickSort(int *arry,int first,int last)
{
    int pivot,temp,i,j;

    if(first != last)
    {
        pivot=first;
        i=first;
        j=last;

        while(i< j)
        {
            while(arry[i]< =arry[pivot]&&i< last)
                i++;
            while(arry[j]>arry[pivot])
                j--;
            if(i< j)
            {
                temp=arry[i];
                arry[i]=arry[j];
                arry[j]=temp;
            }
        }
        temp=arry[pivot];
        arry[pivot]=arry[j];
        arry[j]=temp;
        QuickSort(arry,first,j-1);
        QuickSort(arry,j+1,last);

    }
}

Question Number 250

The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
    int data;
    struct Node *next;
}*StackTop;

void Push(int input);
int Pop();
void Display();

void main()
{

    StackTop=NULL;
    Push(100);
    Push(200);
    Push(300);
    Push(500);
    Pop();
    Display();
}

void Push(int input)
{
    struct Node *temp;
    temp=(struct Node *)malloc(sizeof(struct Node));
    temp->data=input;
    if (StackTop == NULL)
    {
        StackTop=temp;
        StackTop->next=NULL;
    }
    else
    {
        temp->next=StackTop;
        StackTop=temp;
    }
}

int Pop()
{
    struct Node *TopVal;
    int input;
    TopVal=StackTop;
    if(StackTop==NULL)
    {
        printf("\nStack is empty");
        return -1;

    }
    else
    {
        StackTop = TopVal;
        input=TopVal->data;
        free(TopVal);
        return input;
    }
}

void Display()
{
    struct Node *temp=StackTop;
    if(temp!=NULL)
    {
        printf("\nElements are:\n");
        while(temp!=NULL)
        {
            printf("\t%d\n",temp->data);
            temp=temp->next;
        }
        printf("\n");
    }
    else
        printf("\nStack is Empty");
}

Question Number 251

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(rear==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[front];
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 252

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
int queue[ARRAY_SIZE], rear=0, front=0;
#define ARRAY_SIZE 10

void Enqueue(int);
int Dequeue();
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    value=queue[rear++];
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}

Question Number 253

The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);

int main()
{
    int HeapArry[20];
    int i,j,size,tmp,k;
    printf("Enter the number of elements to sort : ");
    scanf("%d",&size);
    printf("Enter the elements : \n");
    for(i=1; i< =size; i++)
    {
        scanf("%d",&HeapArry[i]);
        Insert(HeapArry,i);
    }
    j=size;
    for(i=1; i< =j; i++)
    {
        tmp=HeapArry[1];
        HeapArry[1]=HeapArry[size];
        HeapArry[size]=tmp;
        size--;
        Heapsort(HeapArry,1,size);
    }
    printf("\n Sorted list is : ");
    size=j;
    for(i=1; i< =size; i++)
        printf("%d ",HeapArry[i]);
    getch();
    return 0;
}


void Insert(int *HeapArry, int i)
{
    int tmp;
    tmp=HeapArry[i];
    while((i>1)&&(HeapArry[i/2]< tmp))
    {
        HeapArry[i]=HeapArry[i/2];
        i=i/2;
    }
    HeapArry[i]=tmp;
}


void Heapsort(int *HeapArry, int i, int size)
{
    int tmp,j;
    tmp=HeapArry[i];
    j=i*2;
    while(j< =size)
    {
        if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
            j++;
        if(HeapArry[j]< HeapArry[j/2])
            break;
        HeapArry[j/2]=HeapArry[tmp+1];
        j=j*2;
    }
    HeapArry[j/2]=tmp;
}

Question Number 254

The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
    int key,Mark;
    char name[100];
    struct node *next;
};

struct hash
{
    struct node *head;
    int count;
};

struct hash *hashTable = NULL;
int ElementCount = 0;

struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();

void main()
{
    int NumOfElements, choice, key, mark;
    char name[100];
    printf("Enter the number of elements:");
    scanf("%d", &NumOfElements);
    ElementCount = NumOfElements;
    hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));

    InsertToTable(1001,"Stella",99);
    InsertToTable(1002,"Jenn",88);
    InsertToTable(1003,"Alli",90);
    DeleteFromTable(1002);
    SearchElement(1003);
    DisplayTable();
}


struct node * CreateNode(int key, char *name, int mark)
{
    struct node *newnode;
    newnode = (struct node *)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->Mark = mark;
    strcpy(newnode->name, name);
    newnode->next = NULL;
    return newnode;
}


void InsertToTable(int key, char *name, int mark)
{
    int hashIndex = key % ElementCount;
    struct node *newnode =  CreateNode(key, name, mark);
    if (!hashTable[hashIndex].head)
    {
        hashTable[hashIndex].head = newnode;
        hashTable[hashIndex].count = 1;
        return;
    }
    newnode->next = (hashTable[hashIndex].head);
    hashTable[hashIndex].head = newnode;
    hashTable[hashIndex].count++;
    return;
}


void DeleteFromTable(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *temp, *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Given input is not present in hash Table\n");
        return;
    }
    temp = myNode;
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            flag = 1;
            if (myNode == hashTable[hashIndex].head)
                hashTable[hashIndex].head = myNode->next;
            else
                temp->next = myNode->next;

            hashTable[hashIndex].count--;
            free(myNode);
            break;
        }
        temp = myNode;
        myNode = myNode->next;
    }
    if (flag)
        printf("Data is deleted from Hash Table\n");
    else
        printf("Given data is not present in Hash table\n");
    return;
}

void SearchElement(int key)
{
    int hashIndex = key % ElementCount;
    int flag = 0;
    struct node *myNode;
    myNode = hashTable[hashIndex].head;
    if (!myNode)
    {
        printf("Element is not found in the table \n");
        return;
    }
    while (myNode != NULL)
    {
        if (myNode->key == key)
        {
            printf("StudentID  : %d\n", myNode->key);
            printf("Name     : %s\n", myNode->name);
            printf("Mark      : %d\n", myNode->Mark);
            flag = 1;
            break;
        }
        myNode = myNode->next;
    }
    if (!flag)
        printf("Element unavailable in hash table\n");
    return;
}

void DisplayTable()
{
    struct node *myNode;
    int i;
    for (i = 0; i <  ElementCount; i++)
    {
        if (hashTable[i].count == 0)
            continue;
        myNode = hashTable[i].head;
        if (!myNode)
            continue;
        printf("\nData at index %d :\n", i);
        printf("StudentID   Name          Mark   \n");
        while (myNode != NULL)
        {
            printf("%-12d", myNode->key);
            printf("%-15s", myNode->name);
            printf("%d\n", myNode->Mark);
            myNode = myNode->next;
        }
    }
    return;
}

Question Number 255

The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{

    Enqueue(100);
    Enqueue(200);
    Enqueue(300);
    Enqueue(400);
    Dequeue();
    Display();

}

void Enqueue(int input)
{
    if(front==ARRAY_SIZE)
    {
        printf("\n Queue is full");
        return;
    }
    else
    {
        queue[rear]=input;
        rear=rear+1;
    }
}

int Dequeue()
{
    int value;
    if(front==rear)
    {
        printf("\n Queue is empty");
        return -1;
    }
    front=front+1;
    return value;
}

void Display()
{
    int i;
    printf("\nThe queue elements are:");
    for(i=front; i< rear; i++)
    {
        printf("%d ",queue[i]);
    }
}