#include #include using namespace std; void Rendezes( char alma[], int n ) { char asd; for ( int i = 0; i < n; i++ ) { for ( int j = i + 1; j < n; j++ ) { if ( alma[j] < alma[i] ) { asd = alma[i]; alma[i] = alma[j]; alma[j] = asd; } } } } int Kereses( char alma[], int n, char ker ) { int alsoh = 0; int felsoh = n - 1; int kozep = 0; for ( kozep = (alsoh + felsoh) / 2; felsoh >= alsoh; kozep = ( alsoh + felsoh ) / 2 ) { if ( alma[kozep] == ker ) { return kozep; } if ( alma[kozep] < ker ) { alsoh = kozep + 1; } else { felsoh = kozep - 1; } } return -1; } int main(int argc, char *argv[]) { int n = 10; char alma[n]; int a; char ker = 'a'; for ( int i = 0; i < n; i++ ) { cout << "[" << i+1 << ".]: "; cin >> alma[i]; } Rendezes( alma, n ); a = Kereses(alma, n, ker); cout << a << endl; system("PAUSE"); return EXIT_SUCCESS; }