首页 > 解决方案 > 如何为迭代函数编写递归关系

问题描述

目前我正在做一个项目,我必须提供一个函数的递归关系。问题是该函数是一个迭代函数,我没有设法写出它的递归关系。另外,我不确定这样的事情是否可能。有没有办法为迭代函数编写递归关系。

这是我挣扎的代码:


typedef Pair<Job*>* Schecule;

vector<Schecule>* scheculeJobs(Job* jobs[],int jobCount){
    mergeSort(jobs,0,jobCount - 1 ); // O(nlogn)

    vector<Schecule>* schedules = new vector<Schecule>();

    for (int i = 0; i < jobCount; i++){

        Job* firstJob = jobs[i];

        for(int j = i +1 ; j < jobCount ; j++){

            Job* secondJob = jobs[j];

            Schecule schedule = new Pair<Job*>(firstJob,secondJob);
            schedules->push_back(schedule);
        
            if(schedule->first->deadline == schedule->second->deadline){
                Schecule inverseSchedule = new Pair<Job*> 
                      (secondJob,firstJob);
               schedules->push_back(inverseSchedule);
            }
        }   
    }
    return schedules;
}

标签: c++loopsrecursioniterationtime-complexity

解决方案


推荐阅读