你能找到这个bug吗? [英] can you find the bug?

查看:61
本文介绍了你能找到这个bug吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过我的一些旧代码(目前失业,因此有很多

空闲时间;-)


在以下二进制插入实现中排序,

至少1个bug(尽管它可能是个角落;希望它也是唯一的

bug或者我可能会感到尴尬)。


这对CLC老兵来说可能不是一个很大的挑战,但是希望它会给某些子集提供足够的谜题。这个

新闻组的读者有点挑战(希望在那个

挑战中,这是一个有趣的元素)。

随着所有的学生都要求他们的作业轻松出路

这个新闻组的作业,我想处理这个问题的方法是

(因为我没有一个网站... ...,如果你想检查你的

答案,请随时给我发电子邮件,要求答复,我会回复

(或在这里发布,如果你好吗ieve我不是想让你做我的作业

给我;-)

Jeff

void

BinaryInsertionSort(int * a,size_t n)

{

size_t hi,lo,m,i;

int tmp; < (i = 1;
;我< N; i ++){

lo = 0,hi = i;

m = i> 1;


do {

if(a [i] a [m]){

lo = m + 1;

}否则如果(a [i]< a [m]){

hi = m;

}否则

休息;


m = (hi + lo)> 1;

} while(lo< hi);


if(m< i){

tmp = a [i];

memmove(a + m + 1,a + m,sizeof(type)*(i - m));

a [m] = tmp;

}

}

}

Going through some of my old code (currently unemployed so have a lot of
free time ;-)

In the following implementation of Binary Insertion Sort, there is at
least 1 bug (as corner case as it might be; hopefully it''s also the only
bug or I might be embarrassed).

This probably won''t be much of a challenge to the CLC veterans to find,
but hopefully it will present enough of a puzzle to some subset of this
newsgroup''s readers to be somewhat of a challenge (and hopefully in that
challenge, an element of fun).
With all the students asking for the easy way out with their homework
assignments on this newsgroup, I suppose the way to handle this would be
(since I don''t have a website any longer...), if you want to check your
answer, feel free to email me requesting the answer and I will respond
(or post here if you believe I''m not trying to get you to do my homework
for me ;-)
Jeff
void
BinaryInsertionSort (int *a, size_t n)
{
size_t lo, m, i;
int tmp;
for (i = 1; i < n; i++) {
lo = 0, hi = i;
m = i >1;

do {
if (a[i] a[m]) {
lo = m + 1;
} else if (a[i] < a[m]) {
hi = m;
} else
break;

m = (hi + lo) >1;
} while (lo < hi);

if (m < i) {
tmp = a[i];
memmove (a + m + 1, a + m, sizeof (type) * (i - m));
a[m] = tmp;
}
}
}

推荐答案



" Jeffrey Stedfast" < st ****** @ comcast.netwrote in message

news:tf ************************ ******@comcast.com。 ..

"Jeffrey Stedfast" <st******@comcast.netwrote in message
news:tf******************************@comcast.com. ..

通过我的一些旧代码(目前失业,因此有很多空白时间; /)


在下面的二进制插入排序实现中,有至少
至少1个bug(尽管它可能是一个角落;希望它也是唯一的

bug或者我可能会感到尴尬)。


这对CLC老兵来说可能不是一个挑战,

但是希望它会给这个

新闻组的读者的某些子集提供足够的谜题,这是一个挑战(希望在那个

挑战中,一个有趣的元素。


随着所有的学生要求通过他们的家庭作业轻松完成这个新闻组的
作业,我想要处理的方式这将是

(因为我不再拥有一个网站......),如果你想检查你的

答案,请随时给我发电子邮件请求答案a我会回复

(或者如果你认为我不想让你做我的作业就发布在这里

给我;-)


Jeff


void

BinaryInsertionSort(int * a,size_t n)

{

size_t hi,lo,m,i;

int tmp;


for(i = 1;我< N; i ++){

lo = 0,hi = i;

m = i> 1;


do {

if(a [i] a [m]){

lo = m + 1;

}否则如果(a [i]< a [m]){

hi = m;

}否则

休息;


m = (hi + lo)> 1;

} while(lo< hi);


if(m< i){

tmp = a [i];

memmove(a + m + 1,a + m,sizeof(type)*(i - m));

a [m] = tmp;

}

}

}
Going through some of my old code (currently unemployed so have a lot of
free time ;-)

In the following implementation of Binary Insertion Sort, there is at
least 1 bug (as corner case as it might be; hopefully it''s also the only
bug or I might be embarrassed).

This probably won''t be much of a challenge to the CLC veterans to find,
but hopefully it will present enough of a puzzle to some subset of this
newsgroup''s readers to be somewhat of a challenge (and hopefully in that
challenge, an element of fun).
With all the students asking for the easy way out with their homework
assignments on this newsgroup, I suppose the way to handle this would be
(since I don''t have a website any longer...), if you want to check your
answer, feel free to email me requesting the answer and I will respond
(or post here if you believe I''m not trying to get you to do my homework
for me ;-)
Jeff
void
BinaryInsertionSort (int *a, size_t n)
{
size_t lo, m, i;
int tmp;
for (i = 1; i < n; i++) {
lo = 0, hi = i;
m = i >1;

do {
if (a[i] a[m]) {
lo = m + 1;
} else if (a[i] < a[m]) {
hi = m;
} else
break;

m = (hi + lo) >1;
} while (lo < hi);

if (m < i) {
tmp = a[i];
memmove (a + m + 1, a + m, sizeof (type) * (i - m));
a[m] = tmp;
}
}
}



不编译是一个非常大的角落案例:


错误:`type''unclaclared(首次使用此功能)

Not compiling is a pretty big corner case:

error: `type'' undeclared (first use in this function)


Barry写道:
Barry wrote:

" Jeffrey Stedfast" < st ****** @ comcast.netwrote in message

news:tf ************************ ******@comcast.com。 ..
"Jeffrey Stedfast" <st******@comcast.netwrote in message
news:tf******************************@comcast.com. ..

>通过我的一些旧代码(目前失业所以有很多空闲时间;-)

对于CLC老兵来说,这可能不是一个很大的挑战,但是希望它会给这个
新闻组的某个子集带来足够的谜题。读者有点挑战(希望在那个挑战中,这是一个有趣的元素)。

所有的学生都要求他们做好功课的简单方法这个新闻组的作业,我想处理这个问题的方法是
(因为我不再有网站......),如果你想查看你的答案,请随意给我发电子邮件请求答案,我会回复
(如果你相信我不试试,可以在这里发帖为了让你做我的作业
对我来说;-)

Jeff

void
BinaryInsertionSort(int * a,size_t n)
{
size_t hi,lo,m,i;
int tmp;

for(i = 1;我< N; i ++){
lo = 0,hi = i;
m = i> 1;

做{
if(a [i] a [m] ){
lo = m + 1;
}如果(a [i]< a [m]){
hi = m;
}其他
休息;

m =(hi + lo)> 1;
} while(lo< hi);

if(m< i){
tmp = a [i];
memmove(a + m + 1,a + m,sizeof(type)*(i - m));
a [m] = tmp;
}
}
}
>Going through some of my old code (currently unemployed so have a lot of
free time ;-)

In the following implementation of Binary Insertion Sort, there is at
least 1 bug (as corner case as it might be; hopefully it''s also the only
bug or I might be embarrassed).

This probably won''t be much of a challenge to the CLC veterans to find,
but hopefully it will present enough of a puzzle to some subset of this
newsgroup''s readers to be somewhat of a challenge (and hopefully in that
challenge, an element of fun).
With all the students asking for the easy way out with their homework
assignments on this newsgroup, I suppose the way to handle this would be
(since I don''t have a website any longer...), if you want to check your
answer, feel free to email me requesting the answer and I will respond
(or post here if you believe I''m not trying to get you to do my homework
for me ;-)
Jeff
void
BinaryInsertionSort (int *a, size_t n)
{
size_t lo, m, i;
int tmp;
for (i = 1; i < n; i++) {
lo = 0, hi = i;
m = i >1;

do {
if (a[i] a[m]) {
lo = m + 1;
} else if (a[i] < a[m]) {
hi = m;
} else
break;

m = (hi + lo) >1;
} while (lo < hi);

if (m < i) {
tmp = a[i];
memmove (a + m + 1, a + m, sizeof (type) * (i - m));
a[m] = tmp;
}
}
}



不编译是一个非常大的角落案例:


错误:'type''未声明(首次使用此功能)


Not compiling is a pretty big corner case:

error: `type'' undeclared (first use in this function)



oops,抱歉,将其更改为''int''

oops, sorry, change that to ''int''




是关于m =(hi + lo)> 1;


(hi + lo)可能溢出??


1月28日晚上9:33,Jeffrey Stedfast< stedf ... @ comcast.netwrote:

is it about m = (hi + lo) >1;

( hi+lo ) might overflow ??

On Jan 28, 9:33 pm, Jeffrey Stedfast <stedf...@comcast.netwrote:

Barry写道:
Barry wrote:

" Jeffrey Stedfast" < stedf ... @ comcast.netwrote in message

news:tf *************************** ***@comcast.com。 ..
"Jeffrey Stedfast" <stedf...@comcast.netwrote in message
news:tf******************************@comcast.com. ..

通过我的一些旧代码(目前失业所以有很多

的空闲时间;-)
Going through some of my old code (currently unemployed so have a lot of
free time ;-)


在下面的Binary Insertion Sort实现中,

至少为1 bug(作为可能的角落情况;希望它也是唯一的

错误或者我可能会感到尴尬)。
In the following implementation of Binary Insertion Sort, there is at
least 1 bug (as corner case as it might be; hopefully it''s also the only
bug or I might be embarrassed).


这对CLC老兵来说可能不是一个挑战,

但希望它会给这个

新闻组的读者的某些子集带来足够的谜题,这对某些挑战来说是有挑战性的(希望在那个
中)
挑战,一个有趣的元素)。
This probably won''t be much of a challenge to the CLC veterans to find,
but hopefully it will present enough of a puzzle to some subset of this
newsgroup''s readers to be somewhat of a challenge (and hopefully in that
challenge, an element of fun).


所有学生都要求他们轻松完成家庭作业

这个新闻组的作业,我想处理这个的方法是

(因为我不再有网站......),如果你想检查你的

回答,随时给我发电子邮件请求答案,我会回复

(如果你认为我不想让你做我的作业,可以在这里发帖

对我来说;-)
With all the students asking for the easy way out with their homework
assignments on this newsgroup, I suppose the way to handle this would be
(since I don''t have a website any longer...), if you want to check your
answer, feel free to email me requesting the answer and I will respond
(or post here if you believe I''m not trying to get you to do my homework
for me ;-)


Jeff
Jeff


void

BinaryInsertionSort(int * a,size_t n)

{

size_t hi,lo,m,i;

int tmp;
void
BinaryInsertionSort (int *a, size_t n)
{
size_t lo, m, i;
int tmp;


for(i = 1; i< n; i ++){

lo = 0,hi = i;

m = i> 1;
for (i = 1; i < n; i++) {
lo = 0, hi = i;
m = i >1;


do {

if(a [i] a [如果(a [i]< a [m]){

} hi = m;

}其他

休息;
do {
if (a[i] a[m]) {
lo = m + 1;
} else if (a[i] < a[m]) {
hi = m;
} else
break;


m =(hi + lo)> 1;

} while(lo< hi);
m = (hi + lo) >1;
} while (lo < hi);


if(m< i){

tmp = a [i];

memmove(a + m + 1,a + m,sizeof(type)*(i - m));

a [m] = tmp ;

}

}

}
if (m < i) {
tmp = a[i];
memmove (a + m + 1, a + m, sizeof (type) * (i - m));
a[m] = tmp;
}
}
}


不编译是一个相当大的角落案例:
Not compiling is a pretty big corner case:


错误:`type''undeclared(首次使用此功能)哎呀,对不起,改变到''int'' - 隐藏引用的文字 - 显示引用的文字 -
error: `type'' undeclared (first use in this function)oops, sorry, change that to ''int''- Hide quoted text -- Show quoted text -


这篇关于你能找到这个bug吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆