A blog to help students to learn programming in various languages including C, C++, Java, Python and many more.

Subscribe For Free Latest Updates!

We'll not spam mate! We promise.

Saturday 23 January 2016



     In computer science, a search data structure is any data structure that allows the efficient retrieval of specific items from a set of items, such as a specific record from a database.

The simplest, most general, and least efficient search structure is merely an unordered sequential list of all the items. Locating the desired item in such a list, by the linear search method, inevitably requires a number of operations proportional to the number n of items, in the worst case as well as in the average case. Useful search data structures allow faster retrieval; however, they are limited to queries of some specific kind. Moreover, since the cost of building such structures is at least proportional to n, they only pay off if several queries are to be performed on the same database (or on a database that changes little between queries).
Information source: wikipedia.org


Program:->

Program Screenshot
Output

#include <iostream>
using namespace std;
int main()
{
int loc,n,data,a[100];
cout<<"Enter no. of values: ";
cin>>n;
cout<<"Enter "<<n<<" values: ";
for(int x=0;x<n;x++) {
cin>>a[x];
}
cout<<"Entered array is: "<<"\n";
for(int x=0;x<n;x++) {
cout<<a[x]<<"  ";
}
cout<<"\nEnter data to search: ";
cin>>data;
for(int x=0;x<n;x++) {
if(data==a[x]) {
cout<<"Location is: "<<x<<"\n";
loc=x;
break;
}
loc=x;
}
if(data!=a[loc]) {
cout<<"Element not found\n";
}
return(0);
}


0 comments :

Post a Comment



Copyright © 2016 - ProgrmIt - All Rights Reserved
(Articles Cannot Be Reproduced Without Author Permission.)
Design By : | Powered By: Blogger