0
我需要停止遞歸之後,比方說,30秒C.我的一個嘗試是使用goto
- 儘管建議不使用它,但我無法使用它在不同的功能之間代碼如下:如何在一段時間後停止遞歸C
void func_t(int n, int a, int b, int c, int d, int e, int f, int g, int height, Data *data, time_t start_time){
int cont;
data->level_recursions[height] = data->level_recursions[height] + 1;
if (n<= 1) return;
for (cont = 1; cont <= a; cont++){
data->height = height + 1;
func_t((n/b) - c, a, b, c, d, e, f, g, 1 + height, data);
}
for (cont = 1; cont <= d; cont++) {
data->height = height + 1;
func_t((n/e) - f, a, b, c, d, e, f, g, 1 + height, data);
}
clock_t begin = clock();
for (cont = 1; cont <= fn(n, g); cont++);
clock_t end = clock();
data->level_work[height] = data->level_work[height] + ((double)(end - begin)/CLOCKS_PER_SEC);
}
但在這種情況下, ,我只會回來,對吧?所以,我會執行所有的遞歸。有沒有辦法停止該功能? –
請勿創建全局變量。改爲傳遞'start_time'作爲參數。 – DaBler