Professional Documents
Culture Documents
Data Structure
Data Structure
USING
C
(PRACTICAL FILE)
Submitted To:
Submitted By:
Ms. P. Sujitha
Aditya Kumar
Asst. Prof.(C.S.E.)
03020902813
3RD SEM.
1 | Page
INDEX
S.NO.
EXPERIMENT NAME
DATE
REMARKS
SIGN.
EXPERIMENT NUMBER 01
AIM: - Perform Linear search and Binary search on an array.
2 | Page
lb=mid+1;
for(i=lb;i<=ub;i++)
{
if(arr[i]==find)
printf("no is found at %d",i+1);
}
}
break;
}
getch();
}
EXPERIMENT NUMBER 02
AIM: - To perform the following function in an array
4 | Page
1. Insertion
2. Deletion
3. Sorting
Code:
#include<stdio.h>
#include<conio.h>
#includeSEARCH.h
void insert(int [],int);
void del(int [],int);
void sort(int[],int);
void main()
{
int ar[10],b,i,o;
clrscr();
printf("Enter the number of elements in the array - ");
scanf("%d",&o);
o=o-1;
printf("Enter the array\n");
for(i=0;i<=o;i++)
{
printf("Enter element %d - ",i+1);
scanf("%d",&ar[i]);
}
printf("What do you want to do next?\n1.Insert A value\n2.Delete A value\n3.Sort the array\n");
scanf("%d",&b);
switch(b)
{
case 1:
insert(ar,o);
break;
case 2:
del(ar,o);
break;
case 3:
o=o+1;
sort(ar,o);
break;
default:
printf("Wrong Input");}
getch();
}
void insert(int ar[10],int o)
5 | Page
{
int i,j,k;
printf("Enter the position - ");
scanf("%d",&j);
printf("Enter the Value - ");
scanf("%d",&k);
j=j-1;
for(i=o;i>=j-1;i--)
{
ar[i+1]=ar[i];
}
ar[j]=k;
o=o+1;
printf("The new array is ");
for(i=0;i<=o;i++)
{
printf("%d ",ar[i]);
}
}
void del(int ar[10],int o)
{
int i,j;
printf("Enter the position from where the element is to be deleted - ");
scanf("%d",&j);
j=j-1;
for(i=j;i<=o;i++)
{
ar[i]=ar[i+1];
}
o=o-1;
printf("The new array is ");
for(i=0;i<=o;i++)
{
printf("%d ",ar[i]);
}
}
void sort(int ar[10],int o)
{
int i,j,k,temp;
printf("\nUnsorted Data: ");
for(k=0;k<o;k++)
printf("%5d",ar[k]);
for(i=1;i<o;i++)
6 | Page
{
for(j=0;j<o-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
printf("\nAfter pass %d : ",i);
for(k=0;k<o;k++)
printf("%5d",ar[k]);
}
}
EXPERIMENT NUMBER 03
AIM: - To implement sparse matrix using array.
7 | Page
Code:
#include<stdio.h>
#include<conio.h>
struct matrix
{
int row,col,ele;
}s[10],t[10];
void main()
{
int ar[5][5],b,c,d=1,e=1,f,i,j,count=0;
clrscr();
printf("Enter the number of rows in matrix - ");
scanf("%d",&b);
b=b-1;
printf("Enter the number of columns in matrix - ");
scanf("%d",&c);
c=c-1;
printf("Enter the elements\n");
for(i=0;i<=b;i++)
{for(j=0;j<=c;j++){
printf("Enter element [%d][%d]",i+1,j+1);
scanf("%d",&ar[i][j]);
if(ar[i][j]!=0)
count++;}}
for(i=0;i<=b;i++){
printf("\n");
for(j=0;j<=c;j++){
printf("%d\t",ar[i][j]);}}
s[0].row=b;
s[0].col=c;
s[0].ele=count;
for(i=0;i<=b;i++){
for(j=0;j<=c;j++){
if(ar[i][j]!=0){
s[d].row=i;
s[d].col=j;
s[d].ele=ar[i][j];
d++;}}}
printf("\n");
t[0].row=c;
t[0].col=b;
t[0].ele=count;
for(i=0;i<=c;i++)
8 | Page
{for(j=0;j<=b;j++){
if(ar[i][j]!=0){
t[e].row=j;
t[e].col=i;
t[e].ele=ar[i][j];
e++;}}}
printf("1.To get three tupple matrix\n2.To get transpose matrix\n");
scanf("%d",&f);
switch(f)
{
case 1:
printf("ROW\tCOLUMN\tELEMENT\n");
for(i=0;i<=count;i++){
printf("%d\t",s[i].row+1);
printf("%d\t",s[i].col+1);
printf("%d\t",s[i].ele);
printf("\n");}
break;
case 2:
printf("ROW\tCOLUMN\tELEMENT\n");
for(i=0;i<=count;i++){
printf("%d\t",t[i].row+1);
printf("%d\t",t[i].col+1);
printf("%d\t",t[i].ele);
printf("\n");}
break;
default:
printf("Wrong Input");
}
getch();
}
9 | Page
10 | P a g e