递归_分而治之【二段细分数据(同时进行!)】

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 const int Len = 66;
 6 const int Divs = 6;
 7 
 8 void Subdivide(char ar[], int low, int high, int level);
 9 
10 extern int main01()
11 {
12     char ruler[Len];
13     int i;
14     for(i = 1; i < Len - 2; i ++)
15         ruler[i] = ' ';
16     ruler[Len-1] = '\0';
17     int max = Len-2;
18     int min = 0;
19     ruler[max] = ruler[min] = '|';
20     cout << ruler << endl;
21 
22     for(i = 1; i < Divs; i++)
23     {
24         Subdivide(ruler, min, max, i);
25         cout << ruler << endl;
26         for( int j = 1; j < Len - 2 ; j ++)
27         {
28             ruler[j] = ' ';
29         }
30     }
31     return 0;
32 }
33 
34 
35 void Subdivide(char ar[], int low, int high, int level)
36 {
37     if(level == 0)
38         return;
39     int mid = (low + high) / 2;
40     ar[mid] = '|';
41 
42     Subdivide(ar, low, mid, level-1);
43     Subdivide(ar, mid, high, level-1);
44 }

 

posted @ 2016-06-03 17:11  岑小良  阅读(187)  评论(0编辑  收藏  举报