unit ZT_SongSixOKDate;
interface
Uses
Windows, Classes,SysUtils, Controls;
Type
PSongInfo=^SongInfo ;
SongInfo=Record
Code:string[8];
Name:string[40];
End;
Var
SongInfoList:TList;
function IndexOfSongInfo(Code:String; AList:TList): integer; overload;
function IndexOfSongInfo(Code:String): integer; overload;
function IndexOfSongInfoByZB(Code:String; AList:TList): integer; overload;
function IndexOfSongInfoByZB(Code:String): integer; overload;
function SongInfoDecrement(Code:String): integer;
function SongInfoIncrement(Code,SongName:String): integer;
//初始化数据库
function IniSongInfoIncrement(Code,SongName:String): integer;
implementation
function IndexOfSongInfo(Code:String; AList:TList): integer; overload;
begin
Result := 0;
while (Result < AList.Count) and (PSongInfo(AList.Items[Result]).Code <> Code) do
Inc(Result);
if Result = AList.Count then
Result := -1;
end;
function IndexOfSongInfo(Code:String): integer; overload;
begin
Result := IndexOfSongInfo(Code,SongInfoList);
end;
//********************* 折半查找**********************
function IndexOfSongInfoByZB(Code:String): integer; overload;
begin
Result := IndexOfSongInfoByZB(Code,SongInfoList);
end;
function IndexOfSongInfoByZB(Code:String; AList:TList): integer; overload;
var
L,R,M:Integer;
sCode:integer;
begin
Result := -1;
sCode:=Strtointdef(Code,-1);
if AList.Count=0 then exit;
L:=0;
R:= AList.Count;
While (L<=R) DO
Begin
M:=(l+r) div 2;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)= sCode then
Begin
Result:=M;
Exit;
End;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)< sCode then L:=M+1;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)> sCode then R:=M-1;
End;
end;
//******************************************
function SongInfoDecrement(Code:String): integer;
var
intSongInfoIndex:integer;
_PSongInfo
SongInfo;
begin
Result:=-1;
intSongInfoIndex:= IndexOfSongInfo(Code);
if intSongInfoIndex<>-1 then
begin
_PSongInfo:=PSongInfo(SongInfoList.Items[intSongInfoIndex]);
Dispose(_PSongInfo);
SongInfoList.Delete(intSongInfoIndex);
Result:=intSongInfoIndex;
end;
end;
//初始化数据库
function IniSongInfoIncrement(Code,SongName:String): integer;
var
_PSongInfo
SongInfo;
begin
Result:=0;
New(_PSongInfo);
_PSongInfo.Code := Code;
_PsongInfo.Name := SongName;
SongInfoList.Add(_PSongInfo);
end;
function SongInfoIncrement(Code,SongName:String): integer;
var
intSongInfoIndex:integer;
_PSongInfo
SongInfo;
begin
Result:=0;
intSongInfoIndex:= IndexOfSongInfo(Code);
if intSongInfoIndex=-1 then
begin
New(_PSongInfo);
_PSongInfo.Code := Code;
_PsongInfo.Name := SongName;
SongInfoList.Add(_PSongInfo);
end;
end;
end.