Beruflich Dokumente
Kultur Dokumente
DELETE(LA, N, K, ITEM)
Here LA is linear array with N elements and K is a positive integer such that K<=N. This algorithm deletes the Kth
element from LA.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[5],k=0,item,i,j,n;
cout<<"Enter value of n";
cin>>n;
cout<<"enter the element of the array";
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"The elements of array are"<<endl;
for(i=1;i<=n;i++)
{
cout<<a[i]<<endl;
}
cout<<"Enter the location to delete"<<endl;
cin>>k;
item=a[k];
for(j=k;j<=n;j++)
{
a[j]=a[j+1];
}
cout<<"After deleting the element are"<<endl;
for(i=1;i<=n-1;i++)
{
cout<<"\n"<<a[i];
}
getch();
}
OUTPUT:
PROGRAM NO 7
INSERT( LA , N, K, ITEM)
Here LA is linear array with N elements and K is a positive integer such that K<=N . This algorithm inserts an
element ITEM inti Kth position in LA.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],i,item,j,n,k;
clrscr();
cout<<"Enter value of N"<<endl;
cin>>n;
cout<<"Enter value of array"<<endl;
for(i=1;i<=n;i++)
cin>>a[i];
cout<<"The array is"<<endl;
for(i=1;i<=n;i++)
cout<<a[i]<<endl;
j=n;
while(j>=k)
{
a[j+1]=a[j];
j--;
}
cout<<"Enter position whr u want to insert"<<endl;
cin>>k;
cout<<"Enter elemt to insert"<<endl;
cin>>item;
a[k]=item;
n=n+1;
for(i=1;i<=j;i++)
{
cout<<"The updated array is"<<i<<" = "<<a[i]<<endl;
}
getch();
}
OUTPUT:
ALGORITHM OF LINEAR SEARCH
Here DATA is linear array With N elements and ITEM is a given item of information. This algorithms
finds the location LOC of ITEM in DATA,or sets the LOC=0 if search is unsuccessful.
Here DATA is a sorted array with lower bound LB and upper bound UB, and ITEM is a given item of
information. The variables BEG, END and MID denote, respectively, the beginning, end and middle
locations of a segment of elements of DATA. This algorithms finds the location LOC of ITEM in DATA or
sets LOC=NULL.
BUBBLE (DATA, N)
Here DATA is an array with N elements . This algorithm sorts the elements in DATA.
a) If DATA[PTR]<DATA[PTR+1]
Interchange DATA [PTR] and DATA[PTR+1]
[End of if structure]
b) Set PTR=PTR+1.
[End of inner loop]
[End of step 1 outer loop]
Step4:- Exit.