本文整理汇总了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--;
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
}
示例8: main
int main(int argc, char* argv[])
{
std::cout << "Test" << std::endl ;
recursive(0) ;
func5() ;
recursive(10) ;
return 0 ;
}
示例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;
}
示例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);
}
示例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);
}
}
示例12: recursive
uint64_t recursive(uint64_t n)
{
if (n < 2) {
return 1;
}
return n * recursive(n - 1);
}
示例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;
}
示例14: recursive
int RecursiveTest::recursive(int a) {
if (a == 1) {
return 1;
}
return a * recursive(a - 1);
}
示例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;
}