|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
delphi: binary sort
Posted by bryn.
Student on team #1 from uni. Posted on 11/23/2000 6:00 AM MST hi, this is the code in my prog. basically it reads a file called list.txt and then finds a number which the user entered... prob is it only works for sorted data. and i need to get a sort going! a binary sort would be good! how do i do it? could someone sort it for me? and email it, its kinda important heh brynbush@hotmail.com cheers Bryn unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Findbtn: TButton; Inputbox: TEdit; Label1: TLabel; Label2: TLabel; DispBox: TMemo; outputbox: TMemo; Label3: TLabel; Label4: TLabel; procedure FindbtnClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FindbtnClick(Sender: TObject); var fil:textfile; nam:Array [1..40] of string; num:Array [1..40] of integer; ct:integer; items:integer; high:integer; Mid:integer; Low:integer; Number:integer; begin Assignfile(fil,'c:\delphi\soft124\list.txt'); Reset(Fil); ct:=0; while not(eof(fil)) do begin ct:=ct+1; Readln(fil, num [ct], nam [ct]); DispBox.Lines.Add(Format('%2d %4d %s', [ct, num[ct], nam[ct]])); end; items := ct; outputbox.clear; Number := strtoint(inputbox.text); low := 1; high := items; Inputbox.clear; if Number = num[low] then Outputbox.Lines.Add(format('%3d %s', [low,nam[low]])); if Number num[high] then showmessage('Number Entered is too High') else if Number = num[high] then Outputbox.Lines.Add(format('%3d %s', [high,nam[high]])) else repeat mid := trunc((low+high)/2); if Number = num[mid] then Outputbox.Lines.Add(format('%3d %s', [Mid,nam[Mid]])) else if Number |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Chief Delphi Institute for Better High School Robotics | archiver | 2000 | 2 | 24-06-2002 00:17 |
| Chief Delphi Institute for Better High School Robotics | archiver | 2000 | 0 | 24-06-2002 00:17 |
| Chief Delphi Institute for Better High School Robotics | archiver | 2000 | 0 | 24-06-2002 00:17 |
| Team #48 Delphi E.L.I.T.E./ Xtremachen5 | Travis Hoffman | Robot Showcase | 1 | 23-04-2002 16:47 |
| Delphi Automotive Systems is now just Delphi... | Joe Johnson | General Forum | 10 | 21-03-2002 22:23 |