Posted by MindBreaker at 1:57 AM
Read our previous post
Object:
3. Translate the linear search
algorithm into a program which either find
the location LOC where ITEM appears in ARRAY or return LOC=0.
Source Code;
// Linear
search
#include <iostream>
using namespace std;
class del
{
public:
int
bserach(int arr[10],int
searchval)
{
int
count;
for(count=0;count<10;count++)
{
if(searchval==arr[count])
{
return count;
}
}
return 0;
}
////////////////////////////////////////////////////////
};
void
main()
{
del dl;
int arr[10]={11,22,33,36,45,52,57,60,64,78},
searchl,serch, number;
cout<<"Enter
number to Search : ";
cin>>number;
searchl=dl.bserach(arr,number);
cout<<"
Value found at index number : "<<searchl<<endl;
}
Output:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.