当前位置: 首页>>代码示例>>C++>>正文


C++ recursive函数代码示例

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


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


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