//-------------------------------------------------- //CPPfile: LineareSuche.cpp //Beschreibung: Lineare Suche in einem Array //Autor: Tobias Schwalb & Michael Tansella, ITIV //Erstellt: 13.07.2011 //Version: 1.0 //-------------------------------------------------- #include #include using namespace std; int linearSearch( int key, int *array, int length ); int main() { int key = 10; int database[5] = { 1, 2, 3, 4, 5 }; int length = sizeof( database ) / sizeof( database[0] ); cout << "length: " << length << endl; cout << "key " << key << " found at index " << linearSearch( key, database, length ) << endl; system( "Pause" ); } int linearSearch( int key, int *array, int length ) { int i; for( i = 0; i < length; i++ ) { if( array[i] == key ) { return i; } } return -1; }