void fun(Queue *Q)
{
Stack S; // Say it creates an empty stack S
// Run while Q is not empty
while (!isEmpty(Q))
{
// deQueue an item from Q and push the dequeued item to S
push(&S, deQueue(Q));
}
// Run while Stack S is not empty
while (!isEmpty(&S))
{
// Pop an item from S and enqueue the poppped item to Q
enQueue(Q, pop(&S));
}
}
Above function takes a Queue as an argument and uses a stack S to do processing.
What does the above function do in general?
Which of the following is true about linked list implementation of queue?
Consider the following statements:
i. First-in-first out types of computations are efficiently supported by STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing LISTS on
an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than implementing QUEUES
on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by QUEUES.
Which of the following is correct?
If the element “A”, “B”. “C”, & “D” are Placed in a queue and are deleted one at a time, in what order they will be removed?
New elements are added to the……… of the QUEUE?
What does the following Piece of code do?
Public object function ()
{
If (isEmphy ())
return –999;
else
{
Object high;
high = Queue[front]
return high;
{
{
Which of the following is not an application of Priority QUEUE?
A normal QUEUE, if implemented using an array of size MAX-SIZE, gets full when
Is it possible to create a doubly linked list using only one pointer with every node?
What are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list?
Let n be the number of nodes in linked list, you may assume that n > 8.
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?
struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
Which of the following can be the base case for the recursive implementation used to find the length of linked list?
What is the time complexity of the following iterative implementation used to find the length of a linked list?
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int val;
struct Node *next;
}*head;
int get_len()
{
struct Node *temp = head->next;
int len = 0;
while(temp != 0)
{
len++;
temp = temp->next;
}
return len;
}
int main()
{
int arr[10] = {1,2,3,4,5}, n = 5, i;
struct Node *temp, *newNode;
head = (struct Node*)malloc(sizeof(struct Node));
head->next = 0;
temp = head;
for(i=0; i<n; i++)
{
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->val = arr[i];
newNode->next = 0;
temp->next = newNode;
temp = temp->next;
}
int len = get_len();
printf("%d",len);
return 0;
}
What is the output of following function for start pointing to first node of following linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?