| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:编程的问题,请指点
取消只看楼主 加入收藏
夜晚的茶
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-30
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
编程的问题,请指点
在研究一个编程题目,写出来了,但运行的有问题,请高手指点下:
+++++++++++++++++++++++++++++++++题目++++++++++++++++++++++++++++++++++
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

高手帮忙看下吧,哪里写错了
搜索更多相关主题的帖子: 编程 train connected function whether 
2011-06-30 12:56
快速回复:编程的问题,请指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016595 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved