编程的问题,请指点
在研究一个编程题目,写出来了,但运行的有问题,请高手指点下:+++++++++++++++++++++++++++++++++题目++++++++++++++++++++++++++++++++++
Consider the data type City:
type CityP = ^City;
City = record
cityid: Integer;
next1: CityP;
next2: CityP
end;
So, each city can be connected (by train) to at most two other cities (could be nil).
Write a function
function hasLoop(startCity: CityP): Boolean
that checks whether the network of cities started by startCity has a loop.
Example (symbolic):
startCity = [1,n1,n2] (n1,n2 symbolize pointers
n1 = [2,n3,nil]
n3 = [3,n4,nil]
n4 = [4,n1,n2] <------ loop n1-n3-n4-n1
n2 = [5,nil,nil]
If there is a loop, then it is sufficient to find the first one.
The demonstration of the must include code to build an example city network
with loops and one without loops.
Take care that terminates, i.e. does not run into an infinite loop.
++++++++++++++++++++++++++++++偶的解答+++++++++++++++++++++++++++
implementation {$R *.dfm} const N=3;
type CityP = ^City;
City = record cityid: Integer;
next1: CityP; next2: CityP;
end;
var A:array[1..N] of CityP;
B:array[1..N] of integer;
start, n1,n2,n3,n4,help:CityP;
bool:boolean;
jtring;
i,m,w,k:integer;
procedure TForm2.Button1Click(Sender: TObject);
begin close;
end;
procedure TForm
++++++++++++++++++++++++++++++++++++++++++++++++
有什么问题,指点下,谢谢
做了了编程的研究 ,写出来了 ,但运行有问题 ,请高人指点下,问题在哪里 。
++++++++++++++++++++++++++题目++++++++++++++++++++++++++++
Consider the data type City:
type CityP = ^City;
City = record
cityid: Integer;
next1: CityP;
next2: CityP
end;
So, each city can be connected (by train) to at most two other cities (could be nil).
Write a function
function hasLoop(startCity: CityP): Boolean
that checks whether the network of cities started by startCity has a loop.
Example (symbolic):
startCity = [1,n1,n2] (n1,n2 symbolize pointers
n1 = [2,n3,nil]
n3 = [3,n4,nil]
n4 = [4,n1,n2] <------ loop n1-n3-n4-n1
n2 = [5,nil,nil]
If there is a loop, then it is sufficient to find the first one.
The demonstration of the must include code to build an example city network
with loops and one without loops.
Take care that terminates, i.e. does not run into an infinite loop.
+++++++++++++++++++++++++++++我的解答++++++++++++++++++++++++++++++++
implementation {$R *.dfm} const N=3;
type CityP = ^City;
City = record cityid: Integer;
next1: CityP; next2: CityP;
end;
var A:array[1..N] of CityP;
B:array[1..N] of integer;
start, n1,n2,n3,n4,help:CityP;
bool:boolean;
jtring;
i,m,w,k:integer;
procedure TForm2.Button1Click(Sender: TObject);
begin close;
end;
procedure TForm
高手帮忙看下吧,哪里写错了