Go to Post Maybe someday soon the quote will be, "As American as baseball and FIRST robotics!" - KathieK [more]
Home
Go Back   Chief Delphi > Old Forum Archives > 2000
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-06-2002, 00:30
archiver archiver is offline
Forum Archival System
#0047 (ChiefDelphi)
 
Join Date: May 2001
Location: Pontiac, MI
Posts: 21,214
archiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond reputearchiver has a reputation beyond repute
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
__________________
This message was archived from an earlier forum system. Some information may have been left out. Start new discussion in the current forums, and refer back to these threads when necessary.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 20:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi