• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ recursive函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中recursive函数的典型用法代码示例。如果您正苦于以下问题:C++ recursive函数的具体用法?C++ recursive怎么用?C++ recursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了recursive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: recursive

    void recursive(TreeNode *root, int hight, int &min)
    {
        if (root == NULL)
        {
            return;
        }
        
        hight++;
        if (root->left == NULL && root->right == NULL)
        {
            if (flag == 0)
            {
                min = hight;
                flag = 1;
            }
            else if (min > hight && flag == 1)
            {
                min = hight;
            }
        }
        
        recursive(root->left, hight, min);
        recursive(root->right, hight, min);
//        hight--;
    }
开发者ID:isshe,项目名称:3.LeetCode,代码行数:25,代码来源:MinimunDepthOfBinaryTree.cpp


示例2: main

int main ()
{
	char input[20];
	int testCaseRunning=1;
	while (gets(input))
	{
		printf("%4d. ",testCaseRunning++);
		char temp[100]="", output[100]="";
		unsigned long n = 0 ;
		int term = 1;
		if(strlen(input)>=9)
		{
			sprintf(temp,"%s",&input[strlen(input)-9]);
			input[strlen(input)-9] = '\0';
			sscanf(temp,"%lu",&n);
			recursive(n,term,output);
			term=2;
			if(strstr(output,"kuti")==NULL && strlen(output)!=0)
			{
				sprintf(temp,"kuti %s",output);
				strcpy(output,temp);
			}
		}
		sscanf(input,"%lu",&n);
		recursive(n,term,output);
		if(strcmp(output,"")==0)
			printf("0\n");
		else
			printf("%s\n",output);

	}
    return 0;
}
开发者ID:ssi-anik,项目名称:acm,代码行数:33,代码来源:acm10101.c


示例3: recursive

int			recursive(t_map *map, t_trimino *tetrimino)
{
	int	newpos;

	if (protect_stack(map, tetrimino))
		return (1);
	newpos = find_next_pos(map, tetrimino);
	if (newpos)
	{
		if (newpos <= map->target)
		{
			if (tetrimino->next)
				return (recursive(map, tetrimino->next));
		}
		else
			return (recursive(map, tetrimino));
	}
	else if (tetrimino->prev)
	{
		map_unprint_tetrimino(map, tetrimino);
		return (recursive(map, tetrimino->prev));
	}
	else if (!tetrimino->prev)
		return (1);
	return (0);
}
开发者ID:Lolhomme,项目名称:Fillit,代码行数:26,代码来源:recursive.c


示例4: recursive

struct ListNode *recursive(struct ListNode *head, int n)
{
    if (head == NULL || head->next == NULL)
    {
        return head;
    }
    
    int mid = (n-1) / 2;
    int i = 0;
    struct ListNode *pLeft = head;
    struct ListNode *pRight = NULL;
    struct ListNode *pNode = head;
    
    //分开两部分
    for (i = 0; i < mid; i++)
    {
        pNode = pNode->next;
    }
    pRight = pNode->next;
    pNode->next = NULL;
    
    pLeft = recursive(pLeft, mid+1);
    pRight = recursive(pRight, n-mid-1);
    
    head = Merge(pLeft, pRight);
    
    return head;
}
开发者ID:isshe,项目名称:3.LeetCode,代码行数:28,代码来源:SortList.c


示例5: recursive

//fib(n-1)+fib(n-2) = next_sum
//0,1,1,2,3,5,8,13.....,end of 46,47 will be overflow
int recursive(int num){
    
    int tempsum = 0;
        if(num<=0){return(0);}
        else if(num==1){return(1);}        
       return( recursive(num-1)+recursive(num-2)); 
      
    }
开发者ID:r930709,项目名称:Practice_code,代码行数:10,代码来源:fibonacci_2.c


示例6: recursive

 /** \brief calculates the n-th Fibonacci number by using naive recursion
  *
  * \param n the zero-based index of the desired Fibonacci number
  * \return Returns the n-th Fibonacci number.
  */
 static intT recursive(unsigned int n)
 {
   if (n == 0)
     return f0;
   if (n == 1)
     return f1;
   return recursive(n-1)+recursive(n-2);
 }
开发者ID:striezel,项目名称:leonhard,代码行数:13,代码来源:fibonacci.hpp


示例7: recursive

 void recursive(int left,int right,string s,vector<string> &v){
     if(left == 0 && right == 0){
         v.push_back(s);
         return ;
     }
     if(left > 0){
         recursive(left-1,right,s+'(',v);
     }
     if(right > 0 && right > left){
         recursive(left,right-1,s+')',v);
     }
 }
开发者ID:SumatoAppy,项目名称:leetcode-1,代码行数:12,代码来源:generate-parentheses.cpp


示例8: main

int main(int argc, char* argv[])
{
	std::cout << "Test" << std::endl ;

	recursive(0) ;

	func5() ;

	recursive(10) ;

	return 0 ;
}
开发者ID:killbug2004,项目名称:ftrace,代码行数:12,代码来源:test-linked.cpp


示例9: strobogrammaticInRange

 int strobogrammaticInRange(string low, string high) {
     int len_low = low.length();
     int len_high = high.length();
     int total = 0;
     if (len_low == 0 || len_high == 0) return 0;
     vector<char> nums1 = {'0', '1', '6', '8', '9'};
     vector<char> nums2 = {'0', '1', '9', '8', '6'};
     recursive("", nums1, nums2, low, high, total);
     recursive("0", nums1, nums2, low, high, total);
     recursive("1", nums1, nums2, low, high, total);
     recursive("8", nums1, nums2, low, high, total);
     return total;
 }
开发者ID:candiceyoung,项目名称:leetcode_solutions,代码行数:13,代码来源:strobogrammatic_number_iii.cpp


示例10: recursive

node *recursive(node *curr1,node *curr2,int prev){
	if(NULL==curr1 || NULL==curr2)
		return NULL;
	if(curr1->data<curr2->data)
		return recursive(curr1->next,curr2,prev);
	if(curr2->data<curr1->data)
		return recursive(curr1,curr2->next,prev);
	if(prev!=curr1->data){
		node *temp=createNewNode(curr1->data);
		temp->next=recursive(curr1->next,curr2->next,temp->data);
		return temp;
	}else
		return recursive(curr1->next,curr2->next,prev);
}
开发者ID:vishalkumargourav,项目名称:DSA-AND-ALGO,代码行数:14,代码来源:intersection.c


示例11: recursive

long long recursive(long long d, long long current, long long increment)
{
	if(((d-current) - (current*current)) < 0)
	{
		if( (d-current+1) - ((current-1) * (current-1)) >=0)
			return current-1;
		else
			return recursive(d, current-(increment/2), 1);
	}
	else
	{
		return recursive(d, current + increment, increment*increment);
	}
}
开发者ID:popook88,项目名称:TopCoder,代码行数:14,代码来源:SRM635DIV2P500.cpp


示例12: recursive

uint64_t recursive(uint64_t n)
{
    if (n < 2) {
        return 1;
    }
    return n * recursive(n - 1);
}
开发者ID:dasimagin,项目名称:Algo2016,代码行数:7,代码来源:factorial.cpp


示例13: main

int main()
{
	int total, couple;
	int num1, num2;
	int i;
	int value = 1;
	int result = 0;
	//memset(student, 0, sizeof(student));
	//memset(visited,0,sizeof(visited));
	
	scanf("%d %d", &total, &couple);

	for(int i=0; i<couple; i++){
		scanf("%d %d",&num1,&num2);
		create_node(num1,num2);
	}

	
	for(i=1; i<total+1; i++){
		if( recursive(i,value) )
			value++;
	}

	for(i=1; i<total+1; i++){
		if(visited[i] == 0)
			result++;
	}

	printf("%d\n",result+value-1);
	return 0;
}
开发者ID:huyyang,项目名称:structure,代码行数:31,代码来源:mathReport.c


示例14: recursive

int RecursiveTest::recursive(int a) {
    if (a == 1) {
        return 1;
    }

    return a * recursive(a - 1);
}
开发者ID:greenpea1121,项目名称:DesignPatternExample,代码行数:7,代码来源:RecursiveTest.cpp


示例15: recursive

 int recursive(vector<int> A, vector<int> B, int target, int index, vector<vector<int> >& map){
     //cout<<index<<endl;
     if(index>= A.size())
         return 0;
         
     int diff;
     int minVal=INT_MAX;
     
     for(int i=1;i<100;i++){
         
         if(index!=0 ){
             if(abs(i-B[index-1])>target)
                 continue;
         }
         
         B[index]=i;
         
         if (map[index][i - 1] != INT_MAX) {
             diff = map[index][i - 1];
             minVal = min(diff,minVal);
             continue;
         }
         
         diff = abs(i-A[index]);
         diff += recursive(A,B,target,index+1, map);
         
         minVal = min(diff,minVal);
         map[index][i - 1] = diff;
         
         B[index] = A[index];
         
     }
     
     return minVal;
 }
开发者ID:RongLi1986,项目名称:Algorithms,代码行数:35,代码来源:91_MinimumAdjusmentCost.cpp


示例16: recursive

 void recursive(string temp, vector<char> &nums1, vector<char> &nums2, string &low, string &high, int &total) {
     int len = temp.length();
     if (len > low.length() && len < high.length()) {
         if (len > 1 && temp[0] != '0') total++;
     }
     else if (len == low.length() && len < high.length()) {
         if (compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len == high.length() && len > low.length()) {
         if (compareString(temp, high)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len > high.length()) {
         return;
     }
     else if (len == low.length() && len == high.length()) {
         if (compareString(temp, high) && compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     for (int i = 0; i < nums1.size(); ++i) {
         recursive(nums1[i] + temp + nums2[i], nums1, nums2, low, high, total);
     }
 }
开发者ID:candiceyoung,项目名称:leetcode_solutions,代码行数:30,代码来源:strobogrammatic_number_iii.cpp


示例17: recursive

int recursive (source *src, order *ord, int *p, int *res, int j, int cur, int n){
  //if (j >= n) return 1;
  int i;
  for (i = j; i<n; i++){
    /*int s=0;
      for (s=0; s<n;s++)
      printf("_%d %d\n", res[s], p[i]);*/
      
    if (iscorrect (src, ord, n-1, res, p[i])){
       if (cur > max)
       max = cur;
      res[cur] = p[i];
      
      d = (int**) realloc(d, (size+1)*sizeof(int*));
      d[size] = (int*) malloc(n*sizeof(int));
      memcpy(d[size], res, n*sizeof(int));
      size++;
      
      if (recursive (src, ord, p, res, i+1, cur+1, n)) return 1;
      res[cur] = 0; //backtrace
    }
    //printf("=========\n");
  }

  return 0;
}
开发者ID:paulbilkis,项目名称:coursework,代码行数:26,代码来源:procedure.c


示例18: recursive

void recursive(int i)
{
    if(i<20)
        recursive(++i) ;

	new char[i] ;
}
开发者ID:killbug2004,项目名称:ftrace,代码行数:7,代码来源:test-linked.cpp


示例19: dirFilters

void Parser::parseToConsole()
{

    dirFilters();

#ifdef Q_OS_LINUX
    if(!itsDir->exists(itsArgv[1]))
#else
    if(!itsDir->exists(QString::fromLocal8Bit(itsArgv[1])))
#endif
    {
        qCritical() << "EROR: path to list don't exist\n";
        return;
    }

    QTextStream itsOut(stdout);

#ifdef Q_OS_LINUX
    itsDir->cd(itsArgv[1]);
    itsOut << "ROOT DIR:\n" << QDir::toNativeSeparators(itsArgv[1]) << ":\n";
#else
    itsDir->cd(QString::fromLocal8Bit(itsArgv[1]));
    itsOut << "ROOT DIR:\n" << QDir::toNativeSeparators(QString::fromLocal8Bit(itsArgv[1])) << ":\n";
    itsOut.flush(); // чтобы ROOT DIR выводился в начале, а не в конце
#endif

    if(itsOptions.testFlag(RECURSIVE))
    {
        recursive(itsDir->absolutePath());
    }
    else
    {
        notRecursive(itsDir->absolutePath());
    }
}
开发者ID:BulSV,项目名称:DirList,代码行数:35,代码来源:parser.cpp


示例20: recursive

int recursive(int StartNumber, int Difference, int N) {
	if(N == 0) {
		return 0;
	} else {
		return (StartNumber + recursive((StartNumber+Difference),Difference,(N-1)));
	}    
}
开发者ID:bkmau,项目名称:Example,代码行数:7,代码来源:Req_1.c



注:本文中的recursive函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ recursive_delete函数代码示例发布时间:2022-05-30
下一篇:
C++ rectangle函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap