21BCA1946 Worksheet1.6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Experiment 2.

Student Name: Divya Prakash Singh UID: 21BCA1946


Branch: BCA Section/Group: 21PH-BCA 5B
Semester: 3rd semester Date of Performance: 13/10/2022
Subject Name: DS lab Subject Code: 21CAP-214

1. Aim/Overview of the practical: Write a program to perform enqueue operation using


linked list.

2. Task to be done: Creating a queue using the linked list and performing operations like
enqueue and dequeue on it.

3. Concept used: Linked list, Queue, Insertion, Deletion.

4. Steps/Commands involved to perform practical:


#include <iostream>
using namespace std;

int size, cur_head, cur_tail;

class Node
{
public:
int data;
Node* next;
};

void enqueue(Node* queue_node, int val)


{
if (cur_tail < size)
{
queue_node->data = val;
cur_tail++;
return;
}
else
{
cout << endl << "ERROR: OVERFLOW conditio!" << endl;
}

void dequeue(Node* queue_node)


{
if (cur_head >= 0 && cur_head <= cur_tail)
{
cout << endl << "Value to be dequeued is " << queue_node->data << endl;
queue_node->data = NULL;
cur_head++;
return;
}
else
{
cout << endl << "ERROR: UNDERFLOW condition!" << endl;
}
}

void printQueue(Node* node)


{
while (node != NULL)
{
cout << node->data << " ";
node = node->next;
}

int main(int argc, char const *argv[])


{
int loop = 1;
cout << "Enter the size of queue: ";
cin >> size;

cur_head = 0;
cur_tail = 0;
Node* list[size];
for (int i = 0; i < size; i++)
{
list[i] = new Node();
}
for (int i = 0; i < size; i++)
{
list[i]->data = NULL;
list[i]->next = list[i+1];
if (i == size-1)
{
list[i]->next = NULL;
}
}
int ops;

while (loop == 1)
{
cout << "Select desired operation\n1. For Enqueue operation\n2. For Dequeue operation\n3.
To exit\n";
cin >> ops;

switch (ops)
{
case 1:
int val;
cout << "Enter the value to be inserted: ";
cin >> val;
enqueue(list[cur_tail], val);
break;

case 2:
dequeue(list[cur_head]);
break;

case 3:
loop = 0;
break;

default:
break;
}
}

return 0;
}

5. Result/Output/Writing Summary:

Learning outcomes (What I have learnt):

1. I learned to create a queue using Linked list.

2. I learned to insert an element in queue.

3. And I learned to delete an element from the queue.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet 20
2. Demonstration/Performance / 10
Quiz/Viva

Worksheet Rubrics:
Understanding of Experiment 10% of total grade that is 2 marks

Command Description for all concepts covered in experiment 30% of total grade that is 6marks

Steps Involved in question 40% of total grade that is 8 marks

Writing Output/Screenshot 20% of total grade that is 4 marks

You might also like