Jump to content
A-man

Unique array elements

Recommended Posts

Hello A-man,

 

Here is my procedures I made just few months ago.. Hopefully they help you out. :)

 

deleteDuplicateIntegers:

 

[scar]procedure deleteDuplicateIntegers(var TIA: TIntegerArray);

var

i, i2, h, t: Integer;

tmpTIA: TIntegerArray;

b, za: Boolean;

begin

h:= High(TIA);

SetArrayLength(tmpTIA, (h + 1));

for i:= 0 to h do

begin

for i2:= 0 to t do

begin

b:= (TIA = tmpTIA[i2]);

if(TIA = 0)then

if(not(za))then

begin

za:= True;

Break;

end;

if(b)then

Break;

end;

if(not(b)or(i = 0))then

begin

tmpTIA[t]:= TIA;

Inc(t);

end else

b:= False;

end;

SetArrayLength(TIA, 0);

SetArrayLength(tmpTIA, t);

TIA:= tmpTIA;

SetArrayLength(tmpTIA, 0);

end;[/scar]

 

deleteDuplicateExtendeds:

 

[scar]procedure deleteDuplicateExtendeds(var TEA: TExtendedArray);

var

i, i2, h, t: Integer;

tmpTEA: TExtendedArray;

b, za: Boolean;

begin

h:= High(TEA);

SetArrayLength(tmpTEA, (h + 1));

for i:= 0 to h do

begin

for i2:= 0 to t do

begin

b:= (TEA = tmpTEA[i2]);

if(TEA = 0)then

if(not(za))then

begin

za:= True;

Break;

end;

if(b)then

Break;

end;

if(not(b)or(i = 0))then

begin

tmpTEA[t]:= TEA;

Inc(t);

end else

b:= False;

end;

SetArrayLength(TEA, 0);

SetArrayLength(tmpTEA, t);

TEA:= tmpTEA;

SetArrayLength(tmpTEA, 0);

end;[/scar]

 

deleteDuplicateStrings:

 

[scar]procedure deleteDuplicateStrings(var x: TStringArray);

var

tmp: TStringArray;

i, i2, h, cs: Integer;

begin

h:= High(x);

if(h < 1)then

Exit;

SetArrayLength(tmp, (h + 1));

for i:= 0 to h do

begin

for i2:= 0 to cs do

if(tmp[i2] = x)then

Break;

if(i2 > cs)then

begin

tmp[cs]:= x;

Inc(cs);

end;

end;

SetArrayLength(x, 0);

x:= tmp;

SetArrayLength(x, cs);

SetArrayLength(tmp, 0);

end;[/scar]

 

-Jani

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...