Answer the question
In order to leave comments, you need to log in
I can not finish the program normally?
Algorithm hash tables by chaining, after executing the following commands:
...
Init;
ADD('abc');
ADD('abs');
ADD('bcd');
ADD('cde');
...
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
m = 3;
type
l = ^p;
p = record
k : string;
n : l;
end;
var
a : array [1..m-1] of l;
j : integer;
t : integer;
q : l;
procedure Init;
var i : integer;
begin for i := 0 to m-1 do a[i] := nil; end;
function H(s : string) : integer; begin Result := ord(s[1]) mod 97; end;
function S(k : string) : l;
var b : l; i : integer;
begin
i := H(k);
b := a[i];
while (b <> nil) do
if b.k = k then break
else b := b.n;
Result := b;
end;
function ADD(k : string) : l;
var w, b, z : l; i : integer;
begin
i := H(k);
w := S(k);
z := a[i];
if w = nil then
begin
new(b);
b^.k := k;
b^.n := nil;
if z = nil
then a[i] := b
else w := b;
end;
Result := b;
end;
begin
Init;
ADD('abc');
ADD('abs');
ADD('bcd');
ADD('cde');
if S('abs') <> nil then writeln('find') else writeln('not find');
for j := 0 to m-1 do
begin
q := a[j];
writeln(q.k);
end;
readln;
end.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question