DSA V4 Lab Final Paper
DSA V4 Lab Final Paper
2 40
3 40
100
Page | 1
Question #1
Implement a recursive C++ function which takes an array of integers (arr) and the starting
(start) and ending (end) indices of a portion (part) of this array, and returns the index of the
second largest element present in that portion of array arr. The prototype of your function
should be:
int findSecondLargest (int* arr, int start, int end)
For example, the function call findSecondLargest(arr,3,8) should determine and return the
index of the second largest element present in the array arr between the indices 3 and 8 (both
inclusive).
Question #2
Implement a class for Circular Doubly Linked List (with a dummy header node) which
stores integers in unsorted order. Your class definitions should look like as shown below:
class CDLinkedList;
class DNode {
friend class CDLinkedList;
private:
int data;
DNode* next;
DNode* prev;
};
class CDLinkedList {
private:
DNode head; // Dummy header node
public:
CDLinkedList(); // Default constructor
bool insert (int val); // Inserts val into the linked list. Time complexity: O(1)
bool removeLastValue (int v);
//Note: Remove the last val from the linked list. Time complexity: O(1)
void findMiddleValue(); // find middle value of the linklist and delete it.
void display(); // Displays the contents of linked list on screen …
};
Question #3
In this lab you are going to start implementing a class for creating and storing Binary Search
Trees (BST). Each node of this BST will store the roll number, name and CGPA of a
student. The class definitions will look like:
class StudentBST;
class StudentNode {
friend class StudentBST;
private:
Page | 2
int rollNo; // Student’s roll number (must be unique)
string name; // Student’s name
double cgpa; // Student’s CGPA
StudentNode* left; // Pointer to the left subtree of a node
StudentNode* right; // Pointer to the right subtree of a node
};
class StudentBST {
private:
StudentNode* root; // Pointer to the root node of the tree
public:
StudentBST(); // Default constructor
};
Page | 3