-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.cpp
More file actions
94 lines (83 loc) · 1.6 KB
/
tree.cpp
File metadata and controls
94 lines (83 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <math.h>
#include <string>
#include <stdlib.h>
#include <conio.h>
#define Macase 10
using namespace std;
int data[10]={1,3,0,-3,5,2,100,10,4,6};
int number(int f,int e){
int result;
while(true){
result=rand()%e;
if(result>=f)
return result;
}
}
bool test(int *tab){
for(int i=0;i<Macase;i++){
if(tab[i]>tab[i+1])
return true;
}
return false;
}
void Tree(int F,int E,int *tab){
int paint;
paint=number(F,E);//first number of paint variable
int temp;
for(int i=F;i<paint;i++){
if(tab[i]>paint){
for(int x=E;x>paint;x--){
if(tab[x]<paint){
//change variables of table
temp=tab[x];
tab[x]=tab[i];
tab[i]=temp;
//*************************
}
else{
temp=tab[i];
tab[i]=tab[temp];
tab[temp]=tab[i];
paint=i;
}
}
}
}
for(int j=E;j>paint;j--){
if(tab[j]<paint){
for(int x=F;x<paint;x++){
if(tab[x]>paint){
//change variables of table
temp=tab[x];
tab[j]=tab[j];
tab[j]=temp;
//*************************
}
else{
temp=tab[j];
tab[j]=tab[temp];
tab[temp]=tab[j];
paint=j;
}
}
}
}
/*if(!test(data))
return;
else{
Tree(0,paint-1,data);
Tree(paint+1,E,data);
}*/
}
void aff(int *tab){
for(int i=0;i<Macase;i++){
cout<<*(tab+i)<<" ";
}
}
int main(){
aff(data);cout<<endl;
Tree(0,10,&data[0]);
aff(data);
return 0;
}