1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/*facttail.c*/
#include"facttail.h"
/*facttail*/
int
facttail(
int
n,
int
a)
{
/*Compute a factorialina tail - recursive manner.*/
if
(n < 0)
return
0;
else
if
(n == 0)
return
1;
else
if
(n == 1)
return
a;
else
return
facttail(n - 1, n * a);
}
|
1
2
3
4
5
|
long
Rescuvie(
long
n) {
return
(n == 1) ? 1 : n * Rescuvie(n - 1);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
long
TailRescuvie(
long
n,
long
a) {
return
(n == 1) ? a : TailRescuvie(n - 1, a * n);
}
long
TailRescuvie(
long
n) {
//封装用的
return
(n == 0) ? 1 : TailRescuvie(n, 1);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
void
quickSort(SqList * list ,
int
low ,
int
high)
{
int
pivot;
while
(low<high)
{
pivot=Partition(list,low,high);
quickSort(list, low,pivot - 1);
//quickSort(list,low,pivot-1); 原递归调用
//quickSort(list,pivot+1,high);
low = pivot+1;
/*尾递归*/
}
}
|