Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 669

•  TDictionary Custom Sort  5 800

•  Fast Watermark Sources  5 603

•  3D Designer  8 215

•  Sik Screen Capture  5 913

•  Patch Maker  6 388

•  Айболит (remote control)  6 378

•  ListBox Drag & Drop  5 237

•  Доска для игры Реверси  94 551

•  Графические эффекты  6 570

•  Рисование по маске  5 643

•  Перетаскивание изображений  4 759

•  Canvas Drawing  5 135

•  Рисование Луны  4 863

•  Поворот изображения  4 411

•  Рисование стержней  3 116

•  Paint on Shape  2 360

•  Генератор кроссвордов  3 228

•  Головоломка Paletto  2 551

•  Теорема Монжа об окружностях  3 328

•  Пазл Numbrix  2 200

•  Заборы и коммивояжеры  2 849

•  Игра HIP  1 820

•  Игра Go (Го)  1 740

•  Симулятор лифта  2 072

•  Программа укладки плитки  1 798

•  Генератор лабиринта  2 240

•  Проверка числового ввода  1 925

•  HEX View  2 225

•  Физический маятник  1 911

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Двоичный поиск для TListView



Оформил: DeeCo

{+------------------------------------------------------------ 
| Function ListviewBinarySearch 
| 
| Parameters : 
| listview: listview to search, assumed to be sorted, must 
| be <> nil. 
| Item : item caption to search for, cannot be empty 
| index : returns the index of the found item, or the 
| index where the item should be inserted if it is not 
| already in the list. 
| Returns : True if there is an item with the passed caption 
| in the list, false otherwise. 
| Description: 
| Uses a binary search and assumes that the listview is sorted 
| ascending on the caption of the listitems. The search is 
| case-sensitive, like the default alpha-sort routine used by 
| the TListview class. 
| Note: 
| We use the lstrcmp function for string comparison since it 
| is the function used by the default alpha sort routine. If 
| the listview is sorted by another means (e.g. OnCompare event) 
| this needs to be changed, the comparison method used must 
| always be the same one used to sort the listview, or the 
| search will not work! 
| Error Conditions: none 
| Created: 31.10.99 by P. Below 
+------------------------------------------------------------}

 function ListviewBinarySearch(listview: TListview; const Item: string;
   var Index: Integer): Boolean;
 var
   First, last, pivot, res: Integer;
 begin
   Assert(Assigned(listview));
   Assert(Length(item) > 0);

   Result := False;
   Index  := 0;
   if listview.Items.Count = 0 then Exit;

   First := 0;
   last  := listview.Items.Count - 1;
   repeat
     pivot := (First + last) div 2;
     res   := lstrcmp(PChar(item), PChar(listview.Items[pivot].Caption));
     if res = 0 then
     begin
       { Found the item, return its index and exit. }
       Index  := pivot;
       Result := True;
       Break;
     end { If }
     else if res > 0 then
     begin
       { Item is larger than item at pivot }
       First := pivot + 1;
     end { If }
     else
     begin
       { Item is smaller than item at pivot }
       last := pivot - 1;
     end;
   until last < First;
   Index := First;
 end; { ListviewBinarySearch }




Похожие по теме исходники

Поисковик

Поиск символа

Поиск файлов

Поиск открытых файлов

 

Findup (поиск дублей)

Дейкстра: поиск кратчайшего пути

Нейросеть для распознавания образов

Механизм станка качалки для нефти

 

Весы для взвешивания

Кувшины для воды

Доска для игры Реверси




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте