#include#include #include #include #include #include using namespace std;class dijiuzhang{public: int a[10]; int haxitem[10]; struct Node { int data; Node * rchild; Node * lchild; Node(int a):data(a),rchild(NULL),lchild(NULL) {} Node():rchild(NULL),lchild(NULL) {} }; Node * head; Node * cur; dijiuzhang() { Node * head = new Node(); for(int i = 0 ; i < 10 ; i ++) { int tem; while(1) { int flag = 0; tem = rand()%10; for(int j = 0 ; j < i ; j++) { if(tem == a[j]) { flag = 1; break; } } if(flag==0) { a[i] = tem; break; } } cout< <<" "; for(int i = 0 ; i < 10 ; i++) { haxitem[i] = a[i]; } } cout< b) { high = mid - 1; } else { low = mid + 1; } } cout<<" not find"< data <= tem -> data && cur -> rchild == NULL) { cur -> rchild = tem; cur = head; break; } else if(cur -> data <= tem -> data) { cur = cur -> rchild; } if(cur -> data > tem -> data && cur -> lchild == NULL) { cur -> lchild = tem; cur = head; break; } else if(cur -> data > tem -> data) { cur = cur -> lchild; } } } } void dfs(Node * tem) { if(tem) { dfs(tem -> lchild); cout< data<<" "; dfs(tem -> rchild); } } void haxi()//哈希表 { int tem[10]; int haxibiao[10]; int chongtu[20] = {1,-1,2,-2,3,-3,4,-4,5,-5,6,-6,7,-7,8,-8,9,-9,10,-10}; memset(haxibiao, 0 , sizeof(int)*10); for(int i = 0 ; i < 10 ; i++)tem[i] = haxitem[i]; for(int j = 0 ; j < 10 ; j ++) { int temi = 0; int temchongtu = 0; while(1) { int z = tem[j]% 7 + temchongtu; if(haxibiao[tem[j]%7+temchongtu]==0&&z >= 0) { haxibiao[tem[j]%7+temchongtu] = tem[j]; if(tem[j] == 0) { haxibiao[tem[j]%7+temchongtu] = -1; } temchongtu = 0; temi = 0; break; } else { temchongtu = chongtu[temi++]; } } } cout< >a; duskcl.zheban(a); duskcl.shunxu(a); duskcl.erchapaixushu(); duskcl.dfs(duskcl.head); duskcl.haxi();}