0% found this document useful (0 votes)
30 views11 pages

Data Structure: Practical File OF

Uploaded by

Harman Dhanjal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

Data Structure: Practical File OF

Uploaded by

Harman Dhanjal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PRACTICAL FILE

OF
DATA STRUCTURE

NAME:NAVNEET YADAV
ROLL NO:22405
CLASS:BCA-II

ASSISTANT PROF.
RASHMI ARORA
TRAVERSING AN ARRAY

#include <iostream>
using namespace std;

int main()
{
int a[20],i,n,j;
cout<<"Enter value of array=";
cin>>n;
for(i=0;i<n;i++){
cout<<"Enter array=";
cin>>a[i];
}
cout<<"Enter value of base array=";
cin>>j;
for(i=j-1;i<n;i++){
cout<<a[i]<<endl;
}
return 0;
}
output:
INSERTING AN ARRAY

#include <iostream>

using namespace std;

int main()
{
int a[20],i=0,n,k,num;
cout<<"Enter size of array= ";
cin>>n;

for(i=0;i<n;i++){
cout<<"Enter array "<<i+1<<"=";
cin>>a[i];

}
for(i=0;i<n;i++){
cout<<a[i]<<endl;
}
cout<<"Enter the inserting value=";
cin>>num;
cout<<"enter position=";
cin>>k;

for(i=n;i>=k;i--){
a[i+1]=a[i];
}
a[k-1]=num;
n++;

for(i=0;i<n;i++){
cout<<a[i]<<endl;
}
return 0;
}
Output:
DELETING AN ARRAY

#include <iostream>

using namespace std;

int main()
{
int a[20],i,j,n,k,del;
cout<<"Enter size of array= ";
cin>>n;

for(i=0;i<n;i++){
cout<<"Enter array "<<i+1<<"=";
cin>>a[i];

}
for(i=0;i<n;i++){
cout<<a[i]<<endl;
}
cout<<"Enter position u want to delete=";
cin>>k;
del=a[k-1];
for(i=k-1;i<n-1;i++){
a[i]=a[i+1];
}
n--;
for(i=0;i<n;i++){
cout<<a[i]<<endl;
}
cout<<"deleted item is="<<del;
return 0;
}
Output:
LINEAR SEARCH

#include <iostream>

using namespace std;

int main()
{
int a[20],i=0,n,k;
cout<<"Enter size of array= ";
cin>>n;

for(i=0;i<n;i++){
cout<<"Enter array "<<i+1<<"=";
cin>>a[i];

}
for(i=0;i<n;i++){
cout<<a[i]<<endl;
}
cout<<"enter value to get its address=";
cin>>k;
for(i=0;i<n;i++){
if(a[i]==k){
cout<<"value is present at "<<a[i]<<" location";
break;
}
}
if(a[i]!=k){
cout<<"value is not present";
}

return 0;
}
Output:
BINARY SEARCH

#include <iostream>
using namespace std;

int main()
{
int a[10];
int b=0,e=9,m,i,n,item;
cout<<"How many element=";
cin>>e;

for(i=0;i<e;i++)
{
cout<<"Enter array "<<i+1<<"=";
cin>>a[i];
}
cout<<"Enter element u want to search=";
cin>>item;
for(i=b;i<=e;i++){
m=(b+e)/2;
if(a[m]==item){
cout<<"value is present at "<<m+1<<" position";
break;
}
else if(a[m]>item){
e=m+1;

}
else{
b=m-1;
}
}
if(a[m]!=item){
cout<<"value is not present";
}
return 0;
}
Output:

You might also like