JS 将函数作为参数传递调用

#include<iostream>
using namespace std;


bool find_num(int data[] , int length , int sum , int &first_num , int &second_num)
{
    if(length < 1)
        return true;


    int begin = 0;
    int end = length - 1;


    while(begin < end)
    {
        int current_sum = data[begin] + data[end];


        if(current_sum == sum)
        {
            first_num = data[begin];
            second_num = data[end];
            return true;
        }
        else if(current_sum > sum)
            end--;
        else 
            begin++;
    }
    return false;
}


int main()
{
    int data[] = {1 ,3 , 4 , 7 , 12 , 15};
    int length = sizeof(data)/sizeof(int);
    int first_num = 0 ;
    int second_num = 0;
    int sum = 11;


    if(find_num(data , length , sum , first_num , second_num))
    {
        cout<<first_num<<" "<<second_num<<endl;
    }
    else
        cout<<"不存在"<<endl;


    return 0;
}


JS 将函数作为参数传递调用,布布扣,bubuko.com

JS 将函数作为参数传递调用

上一篇:Apache Spark on ACK


下一篇:[Asp.net]DropDownList改变默认选中项的两种方式