DSA Final Paper: Name
DSA Final Paper: Name
DSA Final Paper: Name
Name:
Sehrish Muneer
Class:
BScs 3rd ‘F’
Subject:
DSA LAB
Submitted To:
Abdul Basit Khan
Submission Date:
12/02/2021
Q# 01
Write a simple program that uses array to print out number of employees having salary more than
5000.
#include <iostream>
int main()
int arr[]={2000,5050,5000,65000,1200,7000,10000,80000};
if(arr[i]>5000)
count++;
return 0;
Q# 02:
Write a C++ program to merge and update element in an array using function:
#include<iostream>
#include<conio.h>
int main()
cin>>size1;
cout<<"Enter Array 1 Elements : ";
cin>>arr1[a];
cin>>size2;
cin>>arr2[a];
merge[a]=arr1[a];
size=size1+size2;
merge[k]=arr2[a];
cout<<merge[a]<<" ";
}
return 0;
Q# 03:
Write a C++ program to insert, delete and display element in the double circular
linked list.
#include<iostream>
#include<cstdio>
#include<cstdlib>
struct nod {
int info;
}*start, *last;
int count = 0;
class circulardoublylist {
public:
nod *create_node(int);
void insert_begin();
void insert_end();
void insert_pos();
void delete_pos();
void search();
void update();
void display();
void reverse();
circulardoublylist() {
start = NULL;
last = NULL;
};
int main() {
int c;
circulardoublylist cdl;
while (1) {
cout<<"1.Insert at Beginning"<<endl;
cout<<"2.Insert at End"<<endl;
cout<<"3.Insert at Position"<<endl;
cout<<"4.Delete at Position"<<endl;
cout<<"5.Update Node"<<endl;
cout<<"6.Search Element"<<endl;
cout<<"7.Display List"<<endl;
cout<<"8.Reverse List"<<endl;
cout<<"9.Exit"<<endl;
cin>>c;
switch(c) {
case 1:
cdl.insert_begin();
break;
case 2:
cdl.insert_end();
break;
case 3:
cdl.insert_pos();
break;
case 4:
cdl.delete_pos();
break;
case 5:
cdl.update();
break;
case 6:
cdl.search();
break;
case 7:
cdl.display();
break;
case 8:
cdl.reverse();
break;
case 9:
exit(1);
default:
cout<<"Wrong choice"<<endl;
return 0;
nod* circulardoublylist::create_node(int v) {
count++;
t = new(struct nod);
t->info = v;
t->n = NULL;
t->p = NULL;
return t;
void circulardoublylist::insert_begin() {
int v;
cin>>v;
t = create_node(v);
start = last = t;
t->n = start;
start->p = t;
start = t;
start->p = last;
last->n = start;
cout<<"Element inserted"<<endl;
void circulardoublylist::insert_end() {
int v;
cin>>v;
t = create_node(v);
start = last = t;
} else {
last->n= t;
t->p= last;
last = t;
start->p = last;
last->n= start;
void circulardoublylist::insert_pos() {
int v, pos, i;
cin>>v;
cin>>pos;
t = create_node(v);
if (pos == 1) {
start = last = t;
} else {
count--;
return;
} else {
count--;
return;
s = start;
ptr = s;
s = s->n;
if (i == pos - 1) {
ptr->n = t;
t->p= ptr;
t->n= s;
s->p = t;
cout<<"Element inserted"<<endl;
break;
void circulardoublylist::delete_pos() {
int pos, i;
return;
return;
s = start;
if(pos == 1) {
count--;
last->n = s->n;
s->n->p = last;
start = s->n;
free(s);
cout<<"Element Deleted"<<endl;
return;
s = s->n;
ptr = s->p;
ptr->n = s->n;
s->n->p = ptr;
if (pos == count) {
last = ptr;
count--;
free(s);
cout<<"Element Deleted"<<endl;
void circulardoublylist::update() {
int v, i, pos;
return;
cin>>pos;
cin>>v;
return;
s = start;
if (pos == 1) {
s->info = v;
cout<<"Node Updated"<<endl;
return;
s->info = v;
cout<<"Node Updated"<<endl;
void circulardoublylist::search() {
int pos = 0, v, i;
return;
cin>>v;
s = start;
pos++;
if (s->info == v) {
flag = true;
s = s->n;
if (!flag)
cout<<"Element not found in the list"<<endl;
void circulardoublylist::display() {
int i;
return;
s = start;
cout<<s->info<<"<->";
s = s->n;
cout<<s->info<<endl;
void circulardoublylist::reverse() {
return;
p1 = start;
p2 = p1->n;
p1->n = NULL;
p1->p= p2;
p2->p = p2->n;
p2->n = p1;
p1 = p2;
p2 = p2->p;
last = start;
start = p1;
cout<<"List Reversed"<<endl;