zoukankan      html  css  js  c++  java
  • 递归

    ---恢复内容开始---

     递归

    递归环境

    #include<cstdio>
    #include<iostream>
    #include<set>
    using namespace std;
    int i=0;
    int a(int n)
    {

    cout<<n<<' '; a(n-1);
    }

    int f2(int begin,int end)
    {
    if(begin>end) return 0;
    cout<<begin<<' ';
    f2(begin+1,end);
    }

    int f(int a[],int begin)
    {
    if(begin==6)return 0;
    cout<<i++<<' ';int x=f(a,begin+1);

    cout<<i++<<' '; return x+a[begin];
    }
    int main()
    {
    //a(10);
    //f2(5,9);
    int a[]={2,5,3,9,12,7};
    int sum=f(a,0);
    cout<<sum;
    }

    f(int n=9)

      f(int n=8)

        f(int n=7)

          :::::::::

             逐层递归,//山里有个庙庙里有个和尚,和尚在跟小和尚讲故事,讲的什么呢,讲的是上里有个庙,庙”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“

               每一层有个环境n      movie  盗梦空间 

  • 相关阅读:
    区块链:术语
    比特币术语表
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
  • 原文地址:https://www.cnblogs.com/shenxiaodou/p/10645140.html
Copyright © 2011-2022 走看看