Data Structure and Algorithms Assignment n02123811l
Data Structure and Algorithms Assignment n02123811l
COMPUTER SCIENCE
WASHINGTON CHIKUNICHAWA
NO2123811L
WASHINGTON CHIKUNICHAWA N02123811L
QUESTION ONE
PART (a)
THE CODE
#include <iostream>
int cqueue[5];
return;
if (front == -1) {
front = 0;
rear = 0;
else {
if (rear == n - 1)
rear = 0;
else
rear = rear + 1;
cqueue[rear] = val ;
void deleteCQ() {
if (front == -1) {
cout<<"Queue Underflow\n";
return ;
if (front == rear) {
WASHINGTON CHIKUNICHAWA N02123811L
front = -1;
rear = -1;
else {
if (front == n - 1)
front = 0;
else
front = front + 1;
void displayCQ() {
if (front == -1) {
cout<<"Queue is empty"<<endl;
return;
if (f <= r) {
cout<<cqueue[f]<<" ";
f++;
else {
while (f <= n - 1) {
cout<<cqueue[f]<<" ";
f++;
f = 0;
while (f <= r) {
cout<<cqueue[f]<<" ";
WASHINGTON CHIKUNICHAWA N02123811L
f++;
cout<<endl;
int main() {
cout<<"1)Insert\n";
cout<<"2)Delete\n";
cout<<"3)Display\n";
cout<<"4)Exit\n";
do {
cin>>ch;
switch(ch) {
case 1:
cin>>val;
insertCQ(val);
break;
case 2:
deleteCQ();
break;
case 3:
displayCQ();
break;
case 4:
cout<<"Exit\n";
break;
default: cout<<"Incorrect!\n";
}
WASHINGTON CHIKUNICHAWA N02123811L
} while(ch != 4);
return 0;
THE OUTPUT
PART (b)
THE CODE
#include <iostream>
#include <set>
int main(){
set<int> s;
set<int>::iterator it;
int q,x;
int qt;
cin >> q;
while(q--){
cin>>qt>>x;
WASHINGTON CHIKUNICHAWA N02123811L
switch(qt){
case 1:s.insert(x);
break;
case 2:s.erase(x);
break;
case 3:it=s.find(x);
if(it==s.end())
cout<<"Not found"<<endl;
else
cout<<"Yes it is found"<<endl;
break;
return 0;
THE OUPTPUT
PART (cii)
SINGLE LINKED LIST
WASHINGTON CHIKUNICHAWA N02123811L
Every node contains some data and a pointer to the next node of the same data type.
The node contains a pointer to the next node meaning that the node stores the
address of the next node in the sequence.
CIRCULAR LINKED LIST
A circular linked is very similar to a singly linked list, the only difference is that in the
circular linked list the last node of the list points to the address of the head.
We can traverse all nodes starting from the head and stop when the next node is
pointing to the head which indicates we have reached the last node.
It is used in implementing round-robin scheduling in system processes
DOUBLY LINKED LIST