DSA Theory Exam
DSA Theory Exam
QUESTION NO 1:
Implement the following class (10)
struct node
int num;
node * next;
};
class LinkList
private:
node * start;
public:
};
Answer:
struct node {
int num;
node* next;
};
class LinkList{
private:
node *start;
public:
node* n1;
node* n2;
return;
merge_sort(&n1);
merge_sort(&n2);
{
node* result = NULL;
if (a == NULL)
return (b);
else if (b == NULL)
return (a);
result = a;
else {
result = b;
return result;
node* fast;
node* slow;
slow = source;
fast = source.next;
fast = fast.next;
if (fast != NULL) {
slow = slow.next;
fast = fast.next;
*frontRef = source;
*backRef = slow.next;
slow.next = NULL;
node = node.next;
new_node.data = new_data;
new_node.next = (*head_ref);
(*head_ref) = new_node;
int constructDemoList()
node* a = NULL;
push(&a, 15);
push(&a, 10);
push(&a, 5);
push(&a, 20);
push(&a, 3);
push(&a, 2);
merge_sort(&a);
printList(a);
return 0;
}
};
void main()
list.constructDemoList();
Question No 2:
Implement the following class (10)
struct flightInfo
int flightId;
int fuel;
};
class PriorityQueue
private:
flightInfo FlightQueue[size];
int tail;
int front;
public:
DeQueueFlighFacingEmergency(int FlightNumber);
};
Answer:
#include <iostream>
struct flightInfo
int flightId;
int fuel;
};
class PriorityQueue
private:
flightInfo FlightQueue[size];
int tail;
int Front;
int counter;
public:
{
flightInfo Stk[size];
int front= 0;
while(FlightQueue[tail-1].flightId != FlightNumber)
{
Stk[front++] = FlightQueue[--tail];
}
tail--;
{
FlightQueue[tail++] = Stk[--front];
}
counter--;
}
};