0% found this document useful (0 votes)
9 views

Data Structure and Algorithms Assignment n02123811l

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Data Structure and Algorithms Assignment n02123811l

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DATA STRUCTURES AND ALGO

COMPUTER SCIENCE

WASHINGTON CHIKUNICHAWA

NO2123811L
WASHINGTON CHIKUNICHAWA N02123811L

QUESTION ONE
PART (a)
THE CODE

#include <iostream>

using namespace std;

int cqueue[5];

int front = -1, rear = -1, n=5;

void insertCQ(int val) {

if ((front == 0 && rear == n-1) || (front == rear+1)) {

cout<<"Queue Overflow \n";

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 ;

cout<<"Element deleted from queue is : "<<cqueue[front]<<endl;

if (front == rear) {
WASHINGTON CHIKUNICHAWA N02123811L

front = -1;

rear = -1;

else {

if (front == n - 1)

front = 0;

else

front = front + 1;

void displayCQ() {

int f = front, r = rear;

if (front == -1) {

cout<<"Queue is empty"<<endl;

return;

cout<<"Queue elements are :\n";

if (f <= r) {

while (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() {

int ch, val;

cout<<"1)Insert\n";

cout<<"2)Delete\n";

cout<<"3)Display\n";

cout<<"4)Exit\n";

do {

cout<<"Enter choice : "<<endl;

cin>>ch;

switch(ch) {

case 1:

cout<<"Input for insertion: "<<endl;

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>

using namespace std;

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

 A doubly linked list is a two-way chain.


 Every node in a doubly linked list has: Data, address of the next node and address of
the previous node
 The purpose of a doubly linked list is to enable both-way traversal while still allowing
non-contiguous memory storage

You might also like