DSA Mid Term Lab Exam S21 1
DSA Mid Term Lab Exam S21 1
1. Students will have total 150 minutes to finish the whole exam. It is up to the students to manage
their time.
Question 1 – 30 Marks
Implement the Linked List using head pointer only (you are not allowed to use tail pointer). Interface
(abstract class) of LinkedList class is given below. Your task is to provide the complete implementation
for this question (a child class having name myLL is required, this myLL class will provide the complete
implementation of the LinkedList class)
Interface:
template<class T>
class LinkedList
{
protected:
Node<T>* head;
public:
LinkedList();
virtual void insertAtEnd(T) = 0;
virtual T deleteFromHead() = 0;
virtual bool isEmpty() = 0;
This study source was downloaded by 100000822629006 from CourseHero.com on 05-02-2022 01:55:25 GMT -05:00
https://www.coursehero.com/file/94242267/DSA-Mid-Term-Lab-Exam-S21-1docx/
University of Central Punjab
Faculty of Information Technology
virtual void display() = 0;
};
Question 2 – 30 Marks
Interface (abstract class) of Queue class is given below (a child class having name myQueue is required,
this myQueue class will provide the complete implementation of the Queue class)
Interface:
template<class T>
class Queue
{
protected:
myLL<T> obj;
public:
virtual bool isEmpty() = 0;
virtual void enqueue(T) = 0;
virtual T dequeue() = 0;
virtual void display() = 0;
};
Question 3 – 30 Marks
Now write a global (non-member) function reverseQueue which should reverse all the contents of the
Queue.
This study source was downloaded by 100000822629006 from CourseHero.com on 05-02-2022 01:55:25 GMT -05:00
https://www.coursehero.com/file/94242267/DSA-Mid-Term-Lab-Exam-S21-1docx/
University of Central Punjab
Faculty of Information Technology
Remember: You are not allowed to use any data structure
other than the one made in Question 2.
Hint: You can use more than one Queues
Question 4 – 10 Marks
Now test the main function and produce the exact output given below. It is mandatory to attach the
screen shot of your output in your submission (it carries marks).
int main()
{
cout << "\n\n---------- Best of Luck for the Exam ---------\n\n";
myQueue<char> q1;
q1.enqueue('D');
q1.enqueue('S');
q1.enqueue('A');
q1.enqueue(' ');
q1.enqueue('L');
q1.enqueue('A');
q1.enqueue('B');
q1.display();
return 0;
}
Output:
This study source was downloaded by 100000822629006 from CourseHero.com on 05-02-2022 01:55:25 GMT -05:00
https://www.coursehero.com/file/94242267/DSA-Mid-Term-Lab-Exam-S21-1docx/
University of Central Punjab
Faculty of Information Technology
This study source was downloaded by 100000822629006 from CourseHero.com on 05-02-2022 01:55:25 GMT -05:00
https://www.coursehero.com/file/94242267/DSA-Mid-Term-Lab-Exam-S21-1docx/
Powered by TCPDF (www.tcpdf.org)