File tree 3 files changed +69
-0
lines changed
3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 82
82
> ![ 最大索引堆优化] ( ./static/index-maxheap-reverse.png )
83
83
- reverse数组more detail
84
84
> ![ reverse] ( ./static/reverse-detail.png )
85
+ - 二项堆
86
+ - 斐波那契堆
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ template <typename Key, typename Value>
5
+ class BST {
6
+
7
+ private:
8
+ struct Node {
9
+ Key key;
10
+ Value value;
11
+ Node *left;
12
+ Node *right;
13
+
14
+ Node (Key key, Value value){
15
+ this ->key = key;
16
+ this ->value = value;
17
+ this ->left = this ->right = NULL ;
18
+ }
19
+ };
20
+ Node *root;
21
+ int count;
22
+
23
+ public:
24
+ BST (){
25
+ root = NULL ;
26
+ count = 0 ;
27
+ }
28
+ ~BST (){
29
+ // TODO: ~BST()
30
+ }
31
+ int size (){
32
+ return count;
33
+ }
34
+ bool isEmpty (){
35
+ return count == 0 ;
36
+ }
37
+
38
+ };
39
+
40
+ int main (){
41
+ cout<<" hello" <<endl;
42
+ return 0 ;
43
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ template <typename T>
6
+
7
+ int binarySearch (T arr[], int n, T target)
8
+ {
9
+ // 在arr[l...r]之间查找target
10
+ int l = 0 , r = n - 1 ;
11
+ while (l <= r)
12
+ {
13
+ int mid = (r - l) / 2 + l;
14
+ if (arr[mid] == target)
15
+ return mid;
16
+ if (target < arr[mid])
17
+ // 在arr[l...mid-1]之间查找target
18
+ r = mid - 1 ;
19
+ else // target > arr[mid]
20
+ // 在arr[mid+1...r]之中查找target
21
+ l = mid + 1 ;
22
+ }
23
+ return -1 ;
24
+ }
You can’t perform that action at this time.
0 commit comments