I'd like to know how to get the values of a set.
For example:
Type TSet = set of 1..50;
Var Test:TSet;
begin
Test:=[12 ,25,15]; //set with some alleatory values
?? //How can i know that this set has 3 itens and the itens are 12,
25 and 15?
end;
Any help is welcome;
Thanks in advance;Mailing lists / fpc-pascal / 2002-12
How to get the values stored in a set
4 messages · 3 people ·
- KKarl Brandt 2
- AAnton Tichawa 1
- UUnknown author 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
On Tuesday 03 December 2002 01:33, Karl Brandt wrote:
hi, karl!
you can test for an element, e. g. 12, with:
if 12 in Test then ..
to count the elements, you can write somthing like
var
I: Integer;
N: Integer;
begin
N := 0;
for I := 1 to 50 do begin
if I in Test then Inc(N);
end;hth,
anton.
Show quoted text 18 lines
Show quoted text 10 lines
Test:=[12, 25, 15, 24, 30, 10, 18, 6];
// member operator 'in'
// A is a member of [B]
if (12 in Test) then begin
//you got 12...
end;
//subset operator '<='
// [A] is a subset of [B] ([B] contains [A])
if ([12, 25, 15] <= Test) then begin
//12, 25, and 15 are in the set...
end;
//superset operator '>='
// [B] is a superset of [A]
// ([B] contains (amoungst others) the contents of [A])
if (Test >= [12, 25, 15]) then begin
//Test contains 12, 25, 15, amoungst others..
end;Please note theat in my explanations I use '[]' where the variable must be a set (or a set variable) and no '[]' where is must be a variable of the type the set contains. I don't know of is simple way to work out the count, though you could write a routine to do this yourself:
function TSetCount(x: TSet): word;
type
TSetBounds = 1..50;
var
i: TSetBounds;
begin
Result := 0;
for i := low(TSetBounds) to high (TSetBounds) do begin
if i in x then inc(result);
end;
end;However, this will not tell you what the contents is.
Hope that helps,
Matt
---------------------------------------------
This message was sent using Mistral WebMail.
http://www.mistral.co.uk/
Thanks for you all !!
