Zbiór

Deklaracja:

type t = set of T0;

Działania na zbiorach

type T = set of T0;
var A,B,C : T;
   x:boolean;
begin
............................
C := A + B;
C := A * B;
C := A – B;
x := A = B; //równość zbiorów
x := A <> B; //not (A=B)
x := A <= B; //A jest podzbiorem B
x := A >=B; //B jest podzbiorem A
x := y in A; //czy y zawiera się w A 
end.

Wyświetlanie najmniejszego elementu ze zbioru

const     N = 100;
var
    x : 1..N;
    A : set of 1..N;
begin
    A := [10,16,12,3,8];
    x :=1;
    while not (x in A) do    x := succ(x);
    writeln(x);
end.

Zliczanie elementów w zbiorze

Const N = 100;
var
    A,A1 : set of 1..N;
    i : byte;
    x : 1..N;
begin
    A := [1,2,6,10];
    i := 0;
    if A <> [] then begin
        x := 1;
        A1 := A;
        repeat
            while not(x in A1) do    x := succ(x);
            inc(i);
            A1 := A1-[x];
        until A1 = [];
    end;
    writeln(i);
end.

Wyświetlanie zawartości zbioru

Const N = 100;
var
    A,A1 : set of 1..N;
    i : byte;
    x : 1..N;
begin
    A := [1,2,6,10];
    i := 0;
    if A <> [] then begin
        x := 1;
        A1 := A;
        repeat
            while not(x in A1) do    x := succ(x);
            inc(i);
            writeln(x); //wyswietlenie na ekran
            A1 := A1-[x];
        until A1 = [];
    end;
    writeln(i);
end.
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License