C Tutorial/Search Sort/Sequential Search — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 10:32, 25 мая 2010

Searching: The Sequential Search

#include<stdio.h>
  int sequential_search(char *items, int count, char key)
  {
    register int t;
    for(t=0; t < count; ++t)
      if(key == items[t]) return t;
    return -1; /* no match */
  }
  int main(void){
     char *str = "asdf";
    
     int index = sequential_search(str, 4, "s");
    
     printf("%d",index);
 
  }
1