需要别人帮助找到错误而不是新代码 [英] Need someone help to find error not new code

查看:77
本文介绍了需要别人帮助找到错误而不是新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre lang="cs">#include<stdio.h><br />
<br />
int *find(int *pa,int *pb,int a,int b)<br />
{<br />
    int *pta,*ptb;<br />
    pta=pa;<br />
    ptb=pb;<br />
<br />
    while(pta<pa+a && ptb<pb+b)<br />
    {<br />
        if(*pta<*ptb)<br />
            pta++;<br />
        else if(*pta>*ptb)<br />
            ptb++;<br />
        else<br />
            return pta;<br />
    }<br />
    return 0;<br />
}<br />
<br />
void main()<br />
{<br />
    int a[]={3,1,2,8,9,4,15,6,31}, b[]={11,54,12,4,41,21,10};<br />
    int *p=NULL;<br />
<br />
    p=find(a,b,sizeof(a)/sizeof(a[0]),sizeof(b)/sizeof(b[0]));<br />
<br />
    printf("the first equal number is %d\n",*p);<br />
}</pre><br />


我只想知道哪里出问题了?希望有人帮忙!谢谢先进!问题是我无法获得正确的答案!


I just want to know where is wrong? hope someone help!thanks advanced! the problem is i can''t get the right answer!

推荐答案

由于您的数字序列未排序,因此,您的算法就被破坏了(而是应该在ab的每个成员上循环,直到找到一个mtach.)
Since your number sequences aren''t ordered, your algorithm, as it stands, is broken (it should instead loop on every member of both a and b until a mtach is found).


这篇关于需要别人帮助找到错误而不是新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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