60 likes | 78 Views
Pertemuan 6. Searching s. Indexed Sequential Search. for (i = 0; i < indxsize && kindex [ i ] <= key; i ++) { if (i == 0) lowlim = 0; //set low limit else lowlim = pindex [i-1]; if (i == indxsize ) hilim = n – 1; //set high limit else hilim = pindex [i]-1; }
E N D
Pertemuan 6 Searchings
Indexed Sequential Search for (i = 0; i < indxsize && kindex[ i ] <= key; i++) { if (i == 0) lowlim = 0; //set low limit else lowlim = pindex[i-1]; if (i == indxsize) hilim = n – 1; //set high limit else hilim = pindex[i]-1; } for (j = lowlim; j <= hilim && k[ j ] != key; j++); //search if (j > hilim) return (-1); else return ( j );
Binary Search low = 0; high = n – 1; while (low <= high) { middle = (low + high)/2; if (key == data[middle]) return(middle); //selesai. if (key < data[middle]) high = middle – 1; else low = middle + 1; } return(-1); //data tidak ditemukan.