This one I get -
I just don't get these 2 programs - Can anyone explain em to me -
Linear Searching :
float data;
float a[10];
int flag=0;
for(i=0; i<10; i++)
{
cin>>a;
}
cin>>data;
for(i=0; i<10; i++)
{
if(a=data)
flag=1;
}
if(flag==1)
cout<<"found";
else
cout<<"not found";
I just don't get these 2 programs - Can anyone explain em to me -
binary searching :
int n, a[10], data, m, l=0, u=m-1, flag=0;
while(flag==0!!u>l)
{
n=(l+u)/2;
if(a[n]==data)
flag=1;
else if(a[m]<data)
l=n+1;
else
u=n-1;
}
if(flag==1)
cout<<"found";
else
cout<<"not found";
bubble sorting :
int a[10];
cout<<"enter 10 nos - ";
for(int p=0; p<10, p++)
cin>>a[p];
for(int i=0; i<10; i++)
{
for(int j=o; j<10-1; j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int a=0, a<10, a++)
cout<<a[a];