Bahria University, Islamabad Campus: Department of Computer Science
Bahria University, Islamabad Campus: Department of Computer Science
INSTRUCTIONS:
I. All questions are compulsory.
II. There are total four questions.
III. Answers should either be typed or handwritten, screenshots of codes on the IDE are not allowed.
i. Node* c omStudents(N ode *h1, Node *h2): The function takes the address of
the heads of the two non-empty lists as arguments and returns the head of a
list containing the data of those students that are enrolled in both courses.
ii. void avgMarks(Node *h): The function takes the head of a non -empty list as
an argument and prints the average marks obtained by the students of the
class.
Page 1 of 2
Enrollment Number: ____________________________
iii. int count(Node *h, int m): The function returns the number of students in a
non-empty list who obtained marks equal to or greater than the value passed
as argument.
i. Which data structure is suitable in the given scenario and why? To keep track
of the incoming patients as they check into a clinic and to assign them to
available doctors on first come first served basis except for when a patient
requiring emergency treatm ent checks in , then he is served first.
ii. Convert the given infix expression into its equivalent postfix expression.
(a/(b-c+d))*(e -a)*c
iv. Considering an empty static circular Queue ADT of size 6, show the contents
of Queue after the fo llowing code snippet is executed . Also show the final
positions of fr ont and rear.
Note*: Initially both front and rear are at 0 index
for ( i n t x = 1 ; x < = 6 ; x + + )
{
q.enqueue(x);
}
for ( i n t i = 1 ; i < = 5 ; i + + )
{
cout<<q.dequeue();
q . e n q u e u e ( q . d e q u e u e() );
}
Questi on # 3 : (4 Marks)
Traverse the given binary tree using the following traversal function and write the
output. Note*: I nitial ly the root of the tr ee is passed as an argument to the
functi on.
void Traversal(Node* temp)
{
if(t e m p = = N U L L )
return;
elseif(temp!=NULL)
{
cout<<temp->data;
Traversal(temp->left);
Tr a v e r s a l ( t e m p - > r i g h t ) ;
co u t < < t e m p - > d a t a ;
}
}
Output: