procedure insertLastSimpul(no : integer; P:TPoint);
var
TempNode: PSimpulNode;
newSimpul : PSimpulNode;
begin
GetMem(newSimpul, SizeOf(TSimpulNode));
AllocNodeSimpul(newSimpul,no,P);
TempNode := @FirstSimpul;
while TempNode^.Next <> nil do
TempNode := TempNode^.Next;
TempNode^.Next:=newSimpul;
end;
var
FirstSimpul : TSimpulNode;
Stefan wrote:Hi,
please try the following...
Replace insertLastSimpul with:
- Code: Select all
procedure insertLastSimpul(no : integer; P:TPoint);
var
TempNode: PSimpulNode;
newSimpul : PSimpulNode;
begin
GetMem(newSimpul, SizeOf(TSimpulNode));
AllocNodeSimpul(newSimpul,no,P);
TempNode := @FirstSimpul;
while TempNode^.Next <> nil do
TempNode := TempNode^.Next;
TempNode^.Next:=newSimpul;
end;
if you don't, Delphi gives a warning "Variable newSimpul might not have been initialized"
I've also replaced the global var FirstSimpul:
- Code: Select all
var
FirstSimpul : TSimpulNode;
Hope this helps
Stefan
unit ulist;
interface
uses Windows;
type
PSisiNode=^TSisiNode;
Sisi = record
aw : integer;
ak : integer;
s : integer;
v : integer;
d : real;
end;
TSisiNode =record
Next : PSisiNode;
Info : Sisi;
end;
var FirstSisi : TSisiNode;
procedure AllocNodeSisi(item :PSisiNode;aw:integer;ak:integer;
s:integer; v:integer);
function getDelay(s: integer; v: integer): real;
procedure insertSisi(aw: integer; ak:integer; s:integer ; v: integer);
procedure DeleteAllSisiSimpul(no:integer);
implementation
procedure AllocNodeSisi(item :PSisiNode;aw:integer;ak:integer;
s:integer; v:integer);
begin
New(item);
item^.Next:=nil;
item^.Info.aw:=aw;
item^.Info.ak:=ak;
item^.Info.s:=s;
item^.Info.v:=v;
item^.Info.d:=getDelay(s,v);
end;
function getDelay(s: integer; v: integer): real;
begin
getDelay:=s/v;
end;
procedure insertSisi(aw: integer; ak:integer; s:integer ; v: integer);
var
Temp:PSisiNode;
found:boolean;
newSisiNode : PSisiNode;
begin
GetMem(newSisiNode, SizeOf(TSisiNode));
AllocNodeSisi(newSisiNode,aw,ak,s,v);
Temp:=@FirstSisi;
found:=false;
if(FirstSisi.Info.aw<>0) then
begin
while((not found) or (aw <= Temp^.Info.aw) or (Temp<>nil) ) do
begin
if((aw=Temp^.Info.aw) and (ak > Temp^.Info.ak)) then
found:=true
else
Temp:=Temp^.Next;
end;
if (found) then //insert after
begin
newSisiNode^.Next:=Temp^.Next;
Temp^.Next:=newSisiNode;
end
else //insert last
Temp^.Next:=newSisiNode;
end
else //insert first
begin
newSisiNode^.next:=@FirstSisi;
FirstSisi:=newSisiNode^;
end;
end;
procedure DeleteAllSisiSimpul(no:integer);
//delete all sisi which aw=no
var
temp:PSisiNode;
prev:PSisiNode;
pdel:PSisiNode;
begin
temp:=@FirstSisi;
//traversal list
if(temp^.Next<>nil) then
begin
while(((temp^.next).Info.aw <> no) and (temp<>nil )) do
temp:=temp^.Next;
prev:=temp;
//deleting
while((temp.Info.aw=no )or(temp.Next<>nil)) do
begin
pdel:=temp;
Dispose(pdel);
temp:=temp^.Next;
end;
prev^.Next:=temp;
end
else
begin
if(FirstSisi.Info.aw=no) then
begin
Dispose(@FirstSisi);
end;
end;
end;
end.
function getDelay(s: integer; v: integer): real;
begin
if (s > 0) and (v > 0) then
getDelay:=s/v
else
getDelay:=0;
end;
procedure insertSisi(aw: integer; ak:integer; s:integer ; v: integer);
...
begin
New(newSisiNode);
AllocNodeSisi(newSisiNode,aw,ak,s,v);
...
if Assigned(FirstSisi) then begin
if(FirstSisi^.Info.aw<>0) then begin
....
else
FirstSisi := newSisiNode;
if(FirstSisi^.Info.aw<>0) then begin
while ((not found) or (aw <= Temp^.Info.aw) or (Temp<>nil) ) do begin
if((aw=Temp^.Info.aw) and (ak > Temp^.Info.ak)) then
found:=true
else
Temp:=Temp^.Next;
endd;
InsertSisi(1, 1, 1, 1);
InsertSisi(1, 2, 3, 4);
while ((not found) or (aw <= Temp^.Info.aw) or (Temp<>nil) ) do begin
if((aw=Temp^.Info.aw) and (ak > Temp^.Info.ak)) then begin
found:=true;
break;
end else
Temp:=Temp^.Next;
end;
Users browsing this forum: No registered users and 0 guests