Множество должно удовлетворять
const
maxDigit = 10000;
ArraySize = maxDigit div (high (byte) + 1);
type
TSet = set of byte;
PSet = ^TSet;
TBigSet = array [0..ArraySize] of PSet;
const
maxDigit = 10000;
ArraySize = maxDigit div (high (byte) + 1);
type
TSet = set of byte;
PSet = ^TSet;
TBigSet = array [0..ArraySize] of PSet;
TSet = array[0 .. pred(amount)] of T;
TSet = array[0 .. pred(amount)] of ^T;
... { тут все предыдушие описания }
procedure CreateSet(var s: TSet);
var i: integer;
begin
for i := 0 to pred(amount) do begin
new(s[i]); s[i]^ := [];
end;
end;
procedure PlusSet(var left: TSet; right: TSet);
var i: integer;
begin
for i := 0 to pred(amount) do
left[i]^ := left[i]^ + right[i]^;
end;
{ А теперь - собственно программа: }
var
first, second: TSet;
begin
CreateSet(first); { Как видишь, удобство использования сведено к нулю }
for i := 2 to 20 do include(first, i);
CreateSet(second);
for i := 12 to 30 do include(second, i);
PlusSet(first, second);
print_set(first);
end.
unit ofset;А как с таким описанием дописать этот модуль?
interface
const
maxDigit = 10000;
ArraySize = maxDigit div (high (byte) + 1);
type
TSet = set of byte;
PSet = ^TSet;
TBigSet = array [0..ArraySize] of PSet;
procedure CreateSet(var s: TBigSet);
procedure include(var s: TBigSet; i: Integer);
procedure exclude(var s: TBigSet; i: Integer);
function is_empty(const s: TBigSet): boolean;
function in_set(const s: TBigSet; i: Integer): boolean;
procedure print_set(s: TBigSet);
procedure PlusSet(const A,B: TBigSet; var C: TBigSet);
implementation
{------------------------------------------------------------------------}
procedure NewSet (var PS:Pset; S:Tset);
begin
new (PS);
PS^:=S;
end;
function GetIndex (i: integer):integer;
begin
result := i div 256
end;
function Number (i: integer): integer;
begin
result := i mod 256;
end;
function FullNumber (index: integer; i_mod: integer): integer;
begin
result := index*256 + i_mod
end;
{------------------------------------------------------------------------}
procedure CreateSet(var s: TBigSet);
var i: integer;
begin
for i := 0 to ArraySize do S[i]:=nil;
end;
{------------------------------------------------------------------------}
procedure PlusSet(const A,B: TBigSet; var C: TBigSet);
var i: integer;
begin
for i := 0 to ArraySize do
if (A[i]=nil) and (B[i]=nil) then
C[i]:=nil
else
if (A[i]=nil) and (B[i]<>nil) then
newset (c[i], b[i]^)
else
if (A[i]<>nil) and (B[i]=nil) then
newset (c[i], a[i]^)
else
if (a[i]<>nil) and (b[i]<>nil) then
newset (c[i], b[i]^+a[i]^)
end;