0% found this document useful (0 votes)
20 views4 pages

DSA Mid Term Lab Exam S21 1

The document provides instructions for a mid-term exam on data structures and algorithms. It includes 4 questions - implementing a linked list, queue using the linked list, reversing a queue, and testing the implementations. Students are instructed to only submit .h and .cpp files and that plagiarism will not be tolerated.

Uploaded by

keemakorma49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

DSA Mid Term Lab Exam S21 1

The document provides instructions for a mid-term exam on data structures and algorithms. It includes 4 questions - implementing a linked list, queue using the linked list, reversing a queue, and testing the implementations. Students are instructed to only submit .h and .cpp files and that plagiarism will not be tolerated.

Uploaded by

keemakorma49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

University of Central Punjab

Faculty of Information Technology

Mid-Term Exam Spring - 2021


Data Structures and Algorithms – Lab

Instructions for Invigilators:

1. Students will have total 150 minutes to finish the whole exam. It is up to the students to manage
their time.

Instructions for Students:

1. Please create file with appropriate name


2. Submit only .h and .cpp files on portal.
3. Late submissions will NOT be considered
4. Create as many classes and functions as required. Remember one function for one functionality.
5. Take care, plagiarism will not be tolerated at any case.
6. No .Rar/Zip files are accepted .
7. The paper is close book and close notes. No cheat sheet allowed.
8. Use meaningful variable names, take care of naming conventions and indentation. 5 Marks will
be deducted for each thing if not followed.

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

Implement Queue (FIFO) using Linked List implemented in task 1.

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.

template<class T> //add this line before the function to make it


work as template
Queue <T> reverseQueue(Queue <T> obj);

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();

myQueue<char> reverseQ1 = reverseQueue(q1);


reverseQ1.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)

You might also like