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

DSREC4 - CopyCOMP2

Uploaded by

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

DSREC4 - CopyCOMP2

Uploaded by

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

CS_s4

COLLEGE OF APPLIED SCIENCE


CHEEMENI, KASARAGOD

MANAGED BY
THE INSTITUTE OF HUMAN RESOURCE DEVELOPMENT
Government of Kerala undertaking
Affiliated to Kannur University

B.Sc Computer Science

LABORATARY RECORD
OF
PROGRAMMING WITH CPP AND DATASTRUCTRE

2022-23

NAME: ____________________

REG.NO: __________________

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

COLLEGE OF APPLIED SCIENCE


CHEEMENI, KASARAGOD

MANAGED BY
THE INSTITUTE OF HUMAN RESOURCES DEVELOPMENT
Government of Kerala Undertaking
Affiliated to Kannur University

RECORD OF PRACTICAL WORK


IN
PROGRAMMING WITH CPP AND DATASTRUCTUERE

REG.NO:____________________

Certified that this is a benefice Record of practical work done in computer Laboratory
By___________________ of fourth semester B.Sc computer science during the period
june 2022 to November 2022

Lecturer in charge

External examiner Internal examiner

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

C++
&
DATA
STRUCTURE

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

SECTION-A

SL. NO Topic Page No

1
Implement dynamic memory allocation using new and
delete operators

2 Implement inline functions

3 Implement static function

4 Implement function overloading

5 Implement friend function

6 Implement parameterized and copy


constructor
7
Implement unary operator overloading

8
Implement binary operator overloading

9
Implement inheritance

10 Implement virtual function

11 Implement virtual base class

12
Implement sequential input and output
operations on file

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

SECTION-A

SL. NO Topic Page No

1 Implement Linear search algorithm and print number


of comparisons
2

10

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

DOUBLY LINKEDLIST

#include<iostream.h>
#include<conio.h>
#include<process.h>
class dlinklist
{
struct dnode
{
dnode*prev;
int data;
dnode*next;
}*p;
public:
dlinklist();
void d_append();
void d_addatbeg();
void d_addafter();
void d_count();
void d_delet();
void d_display();
};
dlinklist::dlinklist()
{
p=NULL;
}
void dlinklist::d_append()
{
int num;
cout<<"\nEnter the data:";
cin>>num;

CAS CHEEMENI
CS_s4

dnode *r,*q;
q=p;
if(p==NULL)
{
q=new dnode;
q->prev=NULL;
q->data=num;
q->next=NULL;
p=q;
}
else
{
while(q->next!=NULL)
{
q=q->next;
}
r=new dnode;
r->data=num;
r->next=NULL;
r->prev=q;
q->next=r;
}
}
void dlinklist::d_addatbeg()
{
dnode *q;
int num;
cout<<"\nEnter the number:";
cin>>num;
q=new dnode;
q->prev=NULL;
q->data=num;
q->next=p;
p->prev=q;
p=q;

CAS CHEEMENI
CS_s4

}
void dlinklist::d_addafter()
{
dnode *q=p;
int num,loc;
cout<<"\nEnter the number:";
cin>>num;
cout<<"\nEnter the location:";
cin>>loc;
for(int i=0;i<loc;i++)
{
q=q->next;
if(q==NULL)
{
cout<<"\nThey are less than"<<loc<<"elements.";
return;
}
}
dnode *temp=new dnode;
temp->data=num;
temp->prev=q;
temp->next=q->next;
temp->next->prev=temp;
q->next=temp;
}
void dlinklist::d_delet()
{
dnode *q=p;
int num;
cout<<"\nEnter the number to delete:";
cin>>num;
while(q!=NULL)
{
if(q->data==num)
{

CAS CHEEMENI
CS_s4

if(q==p)
{
p=p->next;
p->prev=NULL;
}
else
{
if(q->next==NULL)
{
q->prev->next=NULL;
}
else
{
q->prev->next=q->next;
q->next->prev=q->prev;
}
}
cout<<"\nThe element"<<q->data<<"is deleted.";
delete q;
return;
}
q=q->next;
}
}
void dlinklist::d_count()
{
int c=0;
dnode *temp=p;
while(temp!=NULL)
{
temp=temp->next;
c++;
}
cout<<"\nCount:"<<c;

CAS CHEEMENI
CS_s4

}
void dlinklist::d_display()
{
dnode *temp=p;
cout<<"\nThe double linklist is:";
while(temp!=NULL)
{
cout<<temp->data<<"\n";
temp=temp->next;
}
}
void main()
{
clrscr();
dlinklist dl;
int ch;
do
{
cout<<"\n1.APPEND.2.ADD.AT BEG.3.ADD
AFTER.4.COUNT.5.DELETE.6.DISPLAY.7.EXIT.";
cout<<"\nEnter the choice:";
cin>>ch;
switch(ch)
{
case 1:dl.d_append();
break;
case 2:dl.d_addatbeg();
break;
case 3:dl.d_addafter();
break;
case 4:dl.d_count();
break;
case 5:dl.d_delet();
break;
case 6:dl.d_display();
break;

CAS CHEEMENI
CS_s4

case 7:exit(0);
break;
default:cout<<"\nWrong choice.";
}
}while(ch>0);
getch();
}

CAS CHEEMENI
CS_s4

OUTPUT

ENTER THE LIMIT: 5

ENTER THE ELEMENTS: 2 4 1 9 6

ELEMENTS BEFORE SORTING: 2 4 1 9 6


ELEMENTS AFTER SORTING IS: 1 2 4 6 9

CAS CHEEMENI
CS_s4

QUICK SORT

#include<iostream.h>
#include<conio.h>
class quick
{
public:
int l[10],i,n,temp;
int read();
static int split(int *,int,int);
void quick_sort(int first,int last);
void display();
};
int quick::read()
{
int count=0;
cout<<"\nEnter the limit:";
cin>>n;
cout<<"\nEnter the elements:";
for(i=0;i<n;i++)
{
count++;
cin>>l[i];
}
return count;
}
void quick::quick_sort(int first,int last)
{
if(first<last)
{
i=split(l,first,last);
quick_sort(first,i-1);
quick_sort(i+1,last);
CAS CHEEMENI
CS_s4

}
}
int quick::split(int *l,int first,int last)
{
int left,right,temp,loc,pivolt_elt;
left=first+1;
right=last;
pivolt_elt=l[first];
while(left<=right)
{
while(l[left]<pivolt_elt)
{
left=left+1;
}
while(l[right]>pivolt_elt)
{
right=right-1;
}
if(left<right)
{
temp=l[left];
l[left]=l[right];
l[right]=temp;
}
}
temp=l[first];
l[first]=l[right];
l[right]=temp;
loc=right;
return loc;
}
void quick::display()
{
for(i=0;i<n;i++)

CAS CHEEMENI
CS_s4

{
cout<<l[i]<<" ";
}
}
void main()
{
clrscr();
quick q;
int c=q.read();
cout<<"\nElements before sorting:";
q.display();
q.quick_sort(0,c-1);
cout<<"\nElements after sorting is:";
q.display();
getch();
}

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI
CS_s4

CAS CHEEMENI

You might also like