递归如何在以下代码段中起作用? [英] how the recursion works in the following code segment ?

查看:94
本文介绍了递归如何在以下代码段中起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void partition(int arr[],int low,int high){

    int mid;

    if(low<high){>
         mid=(low+high)/2;
         partition(arr,low,mid);    
         partition(arr,mid+1,high);
         
    }
}



在上面的程序中第一次递归会在第二次递归时出现两次?推导我这两个递归过程。



任何帮助都表示赞赏。

感谢mahbub。


in the above program is the first recursion will occur twice for the second recursion ? deduce me this two recursion process.

Any help is appreciated.
Thanks mahbub.

推荐答案

我们无法帮助您:我们无法访问您的数据,这些数据可以准确控制发生的情况。



所以你会有自己这样做。

首先在函数的第一行放置一个断点,然后运行你的应用程序。当它到达断点时,记下arr,low和high中的内容以及单步执行代码,看看各种变量会发生什么。



但是,在你的例子,几乎没有任何事情会发生,因为你所做的只是以递减的间隔递归调用方法,直到整数除法意味着低和高的方法相同...
We can't help you with this: we don't have access to your data which controls exactly what happens.

So you will have to do this yourself.
Start by putting a breakpoint on the first line in the function, and running your application. When it hits the breakpoint, write down what is in arr, low and high and single step through the code, watching what happens to the various variables.

However, in your example, pretty much nothing will happen, since all you do is recursively call the method with progressively smaller intervals until integer division means low and high work out the same...


这篇关于递归如何在以下代码段中起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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