function TForm1.SortedLinkedListInsert(cnew:integer; head:link):link; var Previous:link; found, dupe:boolean; begin found:=false; dupe := false; Previous:=nil; result := nil; repeat If cnew < head^.C then found:=true; If cnew = head^.c then dupe := true; If (cnew > head^.C) then begin Previous:=Head; head:=head^.nextlink; end; until (found) or (head=nil) or (dupe); If not dupe then begin new(linkpoint); linkpoint^.C := cnew; Linkpoint^.nextlink:=Previous^.nextlink; Previous^.nextlink:=linkpoint; Result:=Linkpoint; end; { else MessageDlg('that was a dupe', mterror, [mbok],0); } end;