├── README.md ├── 作业1 绪论 ├── 代码及报告 │ ├── 数据截图,分析.pdf │ └── 源代码 │ │ ├── 冒泡排序.cpp │ │ ├── 冒泡排序(递归).cpp │ │ ├── 实验比较汉诺塔时间复杂度.cpp │ │ ├── 插入排序.cpp │ │ ├── 插入排序(递归).cpp │ │ ├── 汉诺塔(递归).cpp │ │ ├── 汉诺塔(非递归).cpp │ │ ├── 角谷猜想.cpp │ │ ├── 选择排序.cpp │ │ └── 选择排序(递归).cpp └── 作业1 第1章.pdf ├── 作业2 线性结构的存储结构与应用 ├── 代码及报告 │ ├── LinkList.cpp │ ├── SeqList.cpp │ ├── StaticList.cpp │ └── 作业2 测试数据.pdf └── 作业2 线性结构的存储结构与应用.pdf ├── 作业3 树形结构及其应用 ├── 代码及报告 │ ├── work.cpp │ └── 测试数据和结果数据.docx └── 作业3 树形结构及其应用.pdf ├── 作业4 图形结构及其应用 ├── 代码及报告 │ ├── Graph.cpp │ └── 测试数据与结果数据及分析.pdf └── 作业4 图型结构及其应用.pdf ├── 作业5 查找结构与排序方法 ├── 代码及报告 │ ├── BST.cpp │ ├── BinarySearch.cpp │ ├── inputdata1.txt │ ├── inputdata2.txt │ ├── 测试数据及结果数据.docx │ └── 生成测试数据.cpp └── 作业5 查找结构与排序方法.pdf ├── 实验1 线性结构及其应用 ├── 代码及报告 │ ├── calculator.cpp │ ├── calculator.exe │ ├── calculator.o │ ├── in1.txt │ ├── in2.txt │ ├── out.txt │ ├── 实验报告.doc │ └── 实验测试数据和结果数据.docx └── 实验1 线性结构及其应用.pdf ├── 实验2 树形结构及其应用 ├── 代码及报告 │ ├── 1.cpp │ ├── CompressedFile.huffman │ ├── DeCompress_Char.cpp │ ├── Huffman_Char.cpp │ ├── Huffman_Word.cpp │ ├── InputText.txt │ ├── K_Huffman.cpp │ ├── OutputText.txt │ ├── test.in │ ├── 实验报告.doc │ ├── 测试数据和结果数据.docx │ └── 测试文本集.txt └── 实验2 树形结构及其应用.pdf └── 实验3 图形结构及其应用 ├── 代码及报告 ├── Graph.txt ├── 实验报告.doc ├── 最短路径算法.cpp ├── 测试数据与结果数据.docx └── 测试数据图.jpg └── 实验3 图型结构及其应用.pdf /README.md: -------------------------------------------------------------------------------- 1 | # 2021-HIT-course-Datastructure 2 | 哈尔滨工业大学《数据结构与算法》课程作业及实验 3 | -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/数据截图,分析.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/作业1 绪论/代码及报告/数据截图,分析.pdf -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/冒泡排序.cpp: -------------------------------------------------------------------------------- 1 | //直接冒泡排序,升序 2 | #include 3 | 4 | using namespace std; 5 | int main() 6 | { 7 | int array[1000]; 8 | /*读入数据*/ 9 | int n; 10 | int temp; 11 | cin >> n; 12 | for (int i = 0; i> array[i]; 14 | /*排序*/ 15 | for (int i = 0; iarray[j + 1]){ 18 | temp = array[j]; 19 | array[j] = array[j + 1]; 20 | array[j + 1] = temp; 21 | } 22 | } 23 | } 24 | /*输出数据*/ 25 | for (int i = 0; i 3 | using namespace std; 4 | #define swap(a,b) (a=a+b,b=a-b,a=a-b) 5 | void Inpute(int array[], int n); 6 | void BubbleSort(int array[], int n); 7 | void Print(int array[], int n); 8 | int main(void) 9 | { 10 | int array[1000]; 11 | int n; 12 | cin >> n; 13 | Inpute(array, n); 14 | BubbleSort(array, n); 15 | Print(array, n); 16 | return 0; 17 | } 18 | void Inpute(int array[], int n) 19 | { 20 | for (int i = 0; i < n; i++) 21 | cin >> array[i]; 22 | } 23 | void BubbleSort(int array[], int n) 24 | { 25 | if (n == 1) 26 | return; 27 | for (int i = 0; i < n - 1; i++) 28 | { 29 | if (array[i] > array[i + 1]) 30 | { 31 | swap(array[i], array[i + 1]); 32 | } 33 | } 34 | n--; 35 | BubbleSort(array, n); 36 | } 37 | void Print(int array[], int n) 38 | { 39 | for (int i = 0; i 2 | #include 3 | #include 4 | using namespace std; 5 | #define Num 5 6 | //计算15个圆盘的汉诺塔 7 | 8 | void Hanoi(int n, char A, char B, char C);//递归 9 | void Hanoi_N(int n);//非递归 10 | 11 | clock_t start, stop; 12 | double duration;//递归算法耗费时间 13 | double duration_N;//非递归算法耗费时间 14 | int main(void) 15 | { 16 | start=clock(); 17 | Hanoi(Num,'A','B','C'); 18 | stop=clock(); 19 | duration=(double)(stop-start)/CLK_TCK; //CLK_TCK为clock()函数的时间单位,即时钟打点 20 | 21 | start=clock(); 22 | Hanoi_N(Num); 23 | stop=clock(); 24 | duration_N=(double)(stop-start)/CLK_TCK; 25 | cout<<"The time of Hanoi:"< 3 | 4 | using namespace std; 5 | int main() 6 | { 7 | int array[1000]; 8 | /*读入数据*/ 9 | int n; 10 | int temp; 11 | cin >> n; 12 | for (int i = 0; i < n; i++) 13 | cin >> array[i]; 14 | /*排序*/ 15 | for (int i = 1; i < n; i++) { 16 | for (int j = i; j > 0 && array[j - 1] > array[j]; --j) { 17 | temp = array[j]; 18 | array[j] = array[j - 1]; 19 | array[j - 1] = temp; 20 | } 21 | } 22 | /*输出数据*/ 23 | for (int i = 0; i < n; i++) 24 | { 25 | cout << array[i] << " "; 26 | } 27 | cout << '\n'; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/插入排序(递归).cpp: -------------------------------------------------------------------------------- 1 | //直接插入排序(递归),升序 2 | #include 3 | using namespace std; 4 | #define swap(a,b) (a=a+b,b=a-b,a=a-b) 5 | void Inpute(int array[], int n); 6 | void InsertSort(int array[], int n); 7 | void Print(int array[], int n); 8 | int main(void) 9 | { 10 | int array[1000]; 11 | int n; 12 | cin >> n; 13 | Inpute(array, n); 14 | InsertSort(array, n); 15 | Print(array, n); 16 | return 0; 17 | } 18 | void Inpute(int array[], int n) 19 | { 20 | for (int i = 0; i < n; i++) 21 | cin >> array[i]; 22 | } 23 | void InsertSort(int array[], int n) 24 | { 25 | int i; 26 | 27 | if(n == 1) 28 | return; 29 | InsertSort(array, n-1); 30 | int temp = array[n - 1]; 31 | for (i = n - 2; i >= 0 && temp < array[i]; i--) 32 | { 33 | array[i+1] = array[i]; 34 | } 35 | array[i+1] = temp; 36 | } 37 | void Print(int array[], int n) 38 | { 39 | for (int i = 0; i < n; i++) 40 | { 41 | cout << array[i] << " "; 42 | } 43 | cout << '\n'; 44 | } -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/汉诺塔(递归).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void Hanoi(int n, char A, char B, char C); 4 | int main(void) 5 | { 6 | int n; 7 | cout<<"How many?"<>n; 9 | Hanoi(n,'A','B','C'); 10 | return 0; 11 | } 12 | void Hanoi(int n, char A, char B, char C)/*A通过C移动到B*/ 13 | { 14 | if (n == 1) 15 | cout << "move " << n << " from " << A << " to " << C << endl; 16 | else 17 | { 18 | Hanoi(n - 1, A, C, B); 19 | cout << "move " << n << " from " << A << " to " << C << endl; 20 | Hanoi(n - 1, B, A, C); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/汉诺塔(非递归).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | void Hanoi(int n); 5 | int main(void) 6 | { 7 | int n; 8 | cout<<"How many?"<> n; 10 | Hanoi(n); 11 | return 0; 12 | } 13 | void Hanoi(int n) 14 | { 15 | int i, res, t, k; 16 | int s; 17 | res = (1 << n) - 1; 18 | for ( i = 1; i <= res; i++ ) { 19 | for ( t = 2, s = 1; s <= n; s++, t *= 2) 20 | if ( i % t == t / 2 ) 21 | break; 22 | k = i / t; 23 | if ( n % 2 == s % 2 ) { 24 | if ( (k + 1) % 3 == 0 ) 25 | cout << "move " << s << " from " << "B" << " to " << "A" << endl; 26 | if ( (k + 1) % 3 == 1 ) 27 | cout << "move " << s << " from " << "A" << " to " << "C" << endl; 28 | if ( (k + 1) % 3 == 2 ) 29 | cout << "move " << s << " from " << "C" << " to " << "B" << endl; 30 | } 31 | else { 32 | if ( (k + 1) % 3 == 0 ) 33 | cout << "move " << s << " from " << "C" << " to " << "A" << endl; 34 | if ( (k + 1) % 3 == 1 ) 35 | cout << "move " << s << " from " << "A" << " to " << "B" << endl; 36 | if ( (k + 1) % 3 == 2 ) 37 | cout << "move " << s << " from " << "B" << " to " << "C" << endl; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/角谷猜想.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) 4 | { 5 | int i = 0;//记录操作次数 6 | int MaxTimes = 1;//记录最大操作次数 7 | int MaxTimes_n = 2;//记录最大操作次数的 8 | for (int n = 1; n <= 100; n++) 9 | { 10 | int n_pre = n; 11 | cout << n; 12 | while (n > 1) { 13 | if (n % 2) { 14 | n = 3 * n + 1; 15 | i++; 16 | cout << "->" << n; 17 | } 18 | else { 19 | n = n / 2; 20 | i++; 21 | cout << "->" << n; 22 | } 23 | } 24 | n = n_pre; 25 | if (MaxTimes < i) { 26 | MaxTimes = i; 27 | MaxTimes_n = n; 28 | } 29 | cout << '\n' << "Times:" << i << '\n' << endl; 30 | i = 0; 31 | } 32 | cout << "最长序列的数为:" << MaxTimes_n << endl; 33 | cout << "最长操作次数为:" << MaxTimes << endl; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/选择排序.cpp: -------------------------------------------------------------------------------- 1 | //直接选择排序,升序 2 | #include 3 | 4 | using namespace std; 5 | int main() 6 | { 7 | int array[1000]; 8 | /*读入数据*/ 9 | int n; 10 | int m; 11 | int temp; 12 | cin >> n; 13 | for (int i = 0; i < n; i++) 14 | cin >> array[i]; 15 | /*排序*/ 16 | for (int i = 0; i < n-1; i++) { 17 | m = i; 18 | for (int j = i + 1; j < n; j++) { 19 | if (array[j] < array[m]) { 20 | m = j; 21 | } 22 | } 23 | if (m != i) { 24 | temp = array[i]; 25 | array[i] = array[m]; 26 | array[m] = temp; 27 | } 28 | } 29 | /*输出数据*/ 30 | for (int i = 0; i < n; i++) 31 | { 32 | cout << array[i] << " "; 33 | } 34 | cout << '\n'; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /作业1 绪论/代码及报告/源代码/选择排序(递归).cpp: -------------------------------------------------------------------------------- 1 | //直接选择排序(递归),升序 2 | #include 3 | using namespace std; 4 | #define swap(a,b) (a=a+b,b=a-b,a=a-b) 5 | void Inpute(int array[], int n); 6 | void ChioceSort(int array[], int n); 7 | void Print(int array[], int n); 8 | int main(void) 9 | { 10 | int array[1000]; 11 | int n; 12 | cin >> n; 13 | Inpute(array, n); 14 | ChioceSort(array, n); 15 | Print(array, n); 16 | return 0; 17 | } 18 | void Inpute(int array[], int n) 19 | { 20 | for (int i = 0; i < n; i++) 21 | cin >> array[i]; 22 | } 23 | void ChioceSort(int array[], int n) 24 | { 25 | if (n == 1) 26 | return; 27 | int temp=0; 28 | int i; 29 | for (i = 0; i < n; i++) 30 | { 31 | if (array[i] < array[0]) 32 | temp = i; 33 | } 34 | if (temp != 0) 35 | { 36 | swap(array[0], array[temp]); 37 | } 38 | array++; 39 | n--; 40 | ChioceSort(array, n); 41 | } 42 | void Print(int array[], int n) 43 | { 44 | for (int i = 0; i < n; i++) 45 | { 46 | cout << array[i] << " "; 47 | } 48 | cout << '\n'; 49 | } -------------------------------------------------------------------------------- /作业1 绪论/作业1 第1章.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/作业1 绪论/作业1 第1章.pdf -------------------------------------------------------------------------------- /作业2 线性结构的存储结构与应用/代码及报告/LinkList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef struct LNode *LIST; 5 | typedef int ElemType; 6 | struct LNode{ 7 | ElemType data; 8 | LIST next; 9 | }; 10 | typedef LIST Position; 11 | 12 | LIST Input(); //输入数据 13 | void Delete(int p, LIST L); //删除给定元素 14 | void DeleteSame(LIST L); //对于已排好序的线性表,删除所有重复元素的算法 15 | LIST reverse(LIST L); //将线性表逆置 16 | LIST DataMove(int k, LIST L); //线性表循环左移/右移 k 位 17 | LIST Merge(LIST L1, LIST L2); //合并两个非递减的线性表 18 | void Print(LIST L); //打印线性表 19 | void Attach(int data, LIST &Rear); //尾插 20 | LIST Input() 21 | { 22 | LIST p, Rear,t; 23 | int N; 24 | cout << "有多少数据?" << endl; 25 | cin >> N; 26 | cout << "请输入数据:" << endl; 27 | p = new LNode; 28 | p->next = NULL; 29 | Rear = p; 30 | for (int i = 0; i < N; ++i) 31 | { 32 | int data; 33 | cin >> data; 34 | Attach(data, Rear); 35 | } 36 | t = p; 37 | p = p->next; 38 | delete t; 39 | return p; 40 | } 41 | void Delete(int p, LIST L) 42 | { 43 | Position tmp, pre; 44 | int cnt = 0; 45 | pre = L; 46 | while (pre && cnt < p -2) 47 | { 48 | pre = pre->next; 49 | cnt++; 50 | } 51 | if (pre == NULL || cnt != p -2 || pre->next == NULL) 52 | { 53 | cout << "参数错误!" << endl; 54 | } 55 | else 56 | { 57 | tmp = pre->next; 58 | pre->next = tmp->next; 59 | delete tmp; 60 | } 61 | } 62 | void Print(LIST L) 63 | { 64 | LIST p = L; 65 | while (p) 66 | { 67 | cout << p->data << ' '; 68 | p = p->next; 69 | } 70 | } 71 | void DeleteSame(LIST L) 72 | { 73 | LIST cur = L; 74 | while (cur->next) 75 | { 76 | if (cur->data == cur->next->data) 77 | { 78 | cur->next = cur->next->next; 79 | } 80 | else 81 | { 82 | cur = cur->next; 83 | } 84 | } 85 | } 86 | LIST reverse(LIST L) 87 | { 88 | LIST p; 89 | p = NULL; 90 | while(L != NULL){ 91 | LNode *tmp = L->next; 92 | L->next = p; 93 | p = L; 94 | L = tmp; 95 | } 96 | return p; 97 | } 98 | LIST DataMove(int k, LIST L) 99 | { 100 | LIST tail = L; 101 | int len =1; 102 | while(tail->next){ 103 | tail = tail->next; 104 | len++; 105 | } 106 | tail ->next =L; 107 | k = k%len; 108 | for(int i = 0;inext; 110 | } 111 | L=tail->next; 112 | tail->next =NULL; 113 | return L; 114 | } 115 | LIST Merge(LIST L1, LIST L2) 116 | { 117 | if(L1==NULL) 118 | return L2; 119 | else if(L2==NULL) 120 | return L1; 121 | else if(L1->data < L2->data){ 122 | L1->next = Merge(L1->next, L2); 123 | return L1; 124 | } 125 | else{ 126 | L2->next = Merge(L2->next, L1); 127 | return L2; 128 | } 129 | 130 | } 131 | void Attach(int data, LIST &Rear){ 132 | LIST p = new LNode; 133 | p->data = data; 134 | p->next = NULL; 135 | Rear->next = p; 136 | Rear = p; 137 | } 138 | int main() 139 | { 140 | while (1) 141 | { 142 | cout << "1、删除给定元素" << endl; 143 | cout << "2、删除排好序的线性表中的重复数据" << endl; 144 | cout << "3、将线性表逆置" << endl; 145 | cout << "4、将线性表循环右移K位" << endl; 146 | cout << "5、合并两个线性表" << endl; 147 | cout << "6、退出" << endl; 148 | cout << "请输入对应功能的序号:" << endl; 149 | int n; 150 | cin >> n; 151 | if(n==6) 152 | return 0; 153 | LIST L = Input(); 154 | if(n==5){ 155 | LIST L2 = Input(); 156 | cout << "合并后的线性表为:" << endl; 157 | Print(Merge(L, L2)); 158 | getchar(); 159 | getchar(); 160 | } 161 | switch (n) 162 | { 163 | case 1: 164 | int p; 165 | cout << "要删除的元素位置为:" << endl; 166 | cin >> p; 167 | Delete(p, L); 168 | cout << "删除后的线性表为:" << endl; 169 | Print(L); 170 | getchar(); 171 | getchar(); 172 | break; 173 | case 2: 174 | 175 | DeleteSame(L); 176 | cout << "删除后的线性表为:" << endl; 177 | Print(L); 178 | getchar(); 179 | getchar(); 180 | break; 181 | case 3: 182 | cout << "逆置后的线性表为:" << endl; 183 | Print(reverse(L)); 184 | getchar(); 185 | getchar(); 186 | break; 187 | case 4: 188 | int k; 189 | cout << "移动多少位?" << endl; 190 | cin >> k; 191 | cout << "移动后的线性表为:" << endl; 192 | Print(DataMove(k, L)); 193 | getchar(); 194 | getchar(); 195 | break; 196 | case 5: 197 | return 0; 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /作业2 线性结构的存储结构与应用/代码及报告/SeqList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define max 1000 4 | typedef int ElemType; 5 | typedef int Position; 6 | struct LIST 7 | { 8 | ElemType elements[max]; 9 | Position last; 10 | }; 11 | void Initial(LIST &L); //初始化 12 | void Input(LIST &L); //输入数据 13 | void Delete(Position p, LIST &L); //删除给定元素 14 | void DeleteSame(LIST &L); //对于已排好序的线性表,删除所有重复元素的算法 15 | void reverse(LIST &L, int start, int end); //将线性表逆置 16 | void DataMove(int k, LIST &L); //线性表循环左移/右移 k 位 17 | void Merge(LIST &L1, LIST &L2);//合并两个非递减的线性表 18 | void Print(LIST L); //打印线性表 19 | 20 | void Initial(LIST &L) 21 | { 22 | L.last = 0; 23 | } 24 | void Input(LIST &L) 25 | { 26 | int N; 27 | cout << "有多少数据?" << endl; 28 | cin >> N; 29 | while (N > max - 1) 30 | { 31 | cout << "溢出了!" << endl; 32 | cout << "有多少数据?" << endl; 33 | cin >> N; 34 | } 35 | cout << "请输入数据:" << endl; 36 | for (int i = 1; i < N + 1; ++i) 37 | { 38 | cin >> L.elements[i]; 39 | L.last++; 40 | } 41 | } 42 | void Delete(Position p, LIST &L) 43 | { 44 | Position q; 45 | if (p > L.last || p < 1) 46 | cout << "指定位置不存在"<L2.elements[p2]){ 105 | cur = L1.elements[p1]; 106 | p1--; 107 | } 108 | else{ 109 | cur = L2.elements[p2]; 110 | p2--; 111 | } 112 | L1.elements[last] = cur; 113 | last--; 114 | } 115 | } 116 | int main() 117 | { 118 | while (1) 119 | { 120 | cout << "1、删除给定元素" << endl; 121 | cout << "2、删除排好序的线性表中的重复数据" << endl; 122 | cout << "3、将线性表逆置" << endl; 123 | cout << "4、将线性表循环右移K位" << endl; 124 | cout << "5、合并两个线性表" << endl; 125 | cout << "6、退出" << endl; 126 | cout << "请输入对应功能的序号:" << endl; 127 | LIST L; 128 | int n; 129 | cin >> n; 130 | switch (n) 131 | { 132 | case 1: 133 | Initial(L); 134 | Input(L); 135 | int p; 136 | cout << "要删除的元素位置为:" << endl; 137 | cin >> p; 138 | Delete(p, L); 139 | cout << "删除后的线性表为:" << endl; 140 | Print(L); 141 | getchar(); 142 | getchar(); 143 | break; 144 | case 2: 145 | Initial(L); 146 | Input(L); 147 | DeleteSame(L); 148 | cout << "删除后的线性表为:" << endl; 149 | Print(L); 150 | getchar(); 151 | getchar(); 152 | break; 153 | case 3: 154 | Initial(L); 155 | Input(L); 156 | reverse(L,1,L.last); 157 | cout << "逆置后的线性表为:" << endl; 158 | Print(L); 159 | getchar(); 160 | getchar(); 161 | break; 162 | case 4: 163 | Initial(L); 164 | Input(L); 165 | int k; 166 | cout << "移动多少位?" << endl; 167 | cin >> k; 168 | DataMove(k, L); 169 | cout << "移动后的线性表为:" << endl; 170 | Print(L); 171 | getchar(); 172 | getchar(); 173 | break; 174 | case 5: 175 | LIST L2; 176 | Initial(L); 177 | Initial(L2); 178 | Input(L); 179 | Input(L2); 180 | Merge(L, L2); 181 | cout << "合并后的线性表为:" << endl; 182 | Print(L); 183 | getchar(); 184 | getchar(); 185 | break; 186 | case 6: 187 | return 0; 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /作业2 线性结构的存储结构与应用/代码及报告/StaticList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define MaxSize 10 4 | #define ElemType int 5 | typedef struct{ 6 | ElemType data; 7 | int next; 8 | }spacestr; 9 | spacestr SPACE[MaxSize]; 10 | int av; 11 | //初始化 12 | void Initialize(){ 13 | int j; 14 | for(j=0;j>SPACE[p].data; 26 | p = SPACE[p].next; 27 | i++; 28 | } 29 | } 30 | void Print(){ 31 | int p = av; 32 | while(p!=-1){ 33 | cout< 2 | #include 3 | using namespace std; 4 | 5 | #define Max 1000 6 | #define datatype char 7 | #define ElemType BTREE 8 | //输出 9 | int x; 10 | char pre[Max]; 11 | //二叉树宽度递归 12 | int MAX = 0; 13 | int count[100]; 14 | 15 | typedef struct BT_node *BTREE; 16 | struct BT_node{ 17 | BTREE lchild; 18 | BTREE rchild; 19 | datatype data; 20 | }; 21 | typedef struct stack{ 22 | ElemType d[Max]; 23 | int top; 24 | }Stack; 25 | 26 | typedef struct queue{ 27 | int front; 28 | int rear; 29 | ElemType d[Max]; 30 | }Queue; 31 | 32 | //栈操作 33 | void InitStack(Stack &S); 34 | bool StackEmpty(Stack S); 35 | void SPush(Stack &S,ElemType x); 36 | void SPop(Stack &S,ElemType &x); 37 | void STop(Stack S,ElemType &x); 38 | 39 | //队列操作 40 | void InitQueue(Queue &Q); 41 | bool isEmpty(Queue Q); 42 | void EnQueue(Queue &Q,ElemType x); 43 | void DeQueue(Queue &Q,ElemType &x); 44 | 45 | //二叉树操作(1 2题) 46 | void CreatBTre(BTREE &T);//先序序列保存二叉树 47 | void PrintBT(BTREE BT);//打印二叉树 48 | void PreOrderre(BTREE T);//先序遍历,递归 49 | void InOrderre(BTREE T);//中序遍历,递归 50 | void PostOrderre(BTREE T);//后序遍历,递归 51 | void PreOrder(BTREE T);//先序遍历,非递归 52 | void InOrder(BTREE T);//中序遍历,非递归 53 | void PostOrder(BTREE T);//后序遍历,非递归 54 | void LevelOrder(BTREE T);//层次遍历 55 | void Visit(BTREE T);//访问节点 56 | //二叉树算法(3 4题) 57 | bool CheckTree(BTREE T);//判断是否为完全二叉树 58 | int TreeMaxWidthre(BTREE T);//计算二叉树宽度,递归 59 | int TreeMaxWidth(BTREE T);//计算二叉树宽度,非递归 60 | 61 | // 62 | void InitStack(Stack &S){ 63 | S.top = -1; 64 | } 65 | //栈功能 66 | bool StackEmpty(Stack S){ 67 | if(S.top==-1) 68 | return true; 69 | else 70 | return false; 71 | } 72 | void SPush(Stack &S,ElemType x){ 73 | if(S.top==Max-1) 74 | return; 75 | S.d[++S.top] = x; 76 | } 77 | void SPop(Stack &S,ElemType &x){ 78 | if(S.top==-1) 79 | return; 80 | x = S.d[S.top--]; 81 | } 82 | void STop(Stack S,ElemType &x){ 83 | if(S.top==-1) 84 | return; 85 | x = S.d[S.top]; 86 | } 87 | //队列功能 88 | void InitQueue(Queue &Q){ 89 | Q.rear = Q.front = 0; 90 | 91 | } 92 | bool isEmpty(Queue Q){ 93 | if(Q.front==Q.rear) 94 | return true; 95 | else 96 | return false; 97 | } 98 | void EnQueue(Queue &Q,ElemType x){ 99 | if((Q.rear+1)%Max==Q.front) 100 | return; 101 | Q.d[Q.rear] = x; 102 | Q.rear = (Q.rear+1)%Max; 103 | } 104 | void DeQueue(Queue &Q,ElemType &x){ 105 | if(Q.rear==Q.front) 106 | return; 107 | x = Q.d[Q.front]; 108 | Q.front = (Q.front+1)%Max; 109 | } 110 | //树操作 111 | //先序序列建立二叉树、递归 112 | void CreatBTre(BTREE &T){ 113 | datatype ch; 114 | cin>>ch; 115 | 116 | if(ch=='#')T=NULL; 117 | else{ 118 | T = new BT_node; 119 | T->data=ch; 120 | CreatBTre(T->lchild); 121 | CreatBTre(T->rchild); 122 | } 123 | } 124 | void printd(){ 125 | cout<data; 146 | SPush(S,p); 147 | p = p->lchild; 148 | } 149 | else{ 150 | pre[x++]='#'; 151 | SPop(S,p); 152 | p=p->rchild; 153 | } 154 | } 155 | pre[x++]='#'; 156 | x=0; 157 | printd(); 158 | cout<data<<' '; 162 | } 163 | void PreOrderre(BTREE T){ 164 | if(T!=NULL){ 165 | Visit(T); 166 | PreOrderre(T->lchild); 167 | PreOrderre(T->rchild); 168 | } 169 | } 170 | void InOrderre(BTREE T){ 171 | if(T!=NULL){ 172 | InOrderre(T->lchild); 173 | Visit(T); 174 | InOrderre(T->rchild); 175 | } 176 | } 177 | void PostOrderre(BTREE T){ 178 | if(T!=NULL){ 179 | PostOrderre(T->lchild); 180 | PostOrderre(T->rchild); 181 | Visit(T); 182 | } 183 | } 184 | void PreOrder(BTREE T){ 185 | BTREE p = T; 186 | Stack S; 187 | InitStack(S); 188 | while(p||!StackEmpty(S)){ 189 | if(p){ 190 | Visit(p); 191 | SPush(S,p); 192 | p = p->lchild; 193 | } 194 | else{ 195 | SPop(S,p); 196 | p = p->rchild; 197 | } 198 | } 199 | } 200 | void InOrder(BTREE T){ 201 | BTREE p = T; 202 | Stack S; 203 | InitStack(S); 204 | while(p||!StackEmpty(S)){ 205 | if(p){ 206 | SPush(S,p); 207 | p = p->lchild; 208 | } 209 | else{ 210 | SPop(S,p); 211 | Visit(p); 212 | p = p->rchild; 213 | } 214 | } 215 | } 216 | void PostOrder(BTREE T){ 217 | Stack S; 218 | InitStack(S); 219 | BTREE p = T; 220 | BTREE tag = NULL;//记录是否从右子节点返回 221 | while(p||!StackEmpty(S)){ 222 | if(p){ 223 | SPush(S,p); 224 | p = p->lchild; 225 | } 226 | else{ 227 | STop(S,p); 228 | if(p->rchild&&p->rchild!=tag) 229 | p = p->rchild; 230 | else{ 231 | SPop(S,p); 232 | Visit(p); 233 | tag = p; 234 | p = NULL;//节点弹出,p指针重置 235 | } 236 | } 237 | } 238 | } 239 | void LevelOrder(BTREE T){ 240 | Queue Q; 241 | InitQueue(Q); 242 | BTREE p; 243 | EnQueue(Q,T); 244 | while(!isEmpty(Q)){ 245 | DeQueue(Q,p); 246 | Visit(p); 247 | if(p->lchild) 248 | EnQueue(Q,p->lchild); 249 | if(p->rchild) 250 | EnQueue(Q,p->rchild); 251 | } 252 | } 253 | bool CheckTree(BTREE T){ 254 | Queue Q; 255 | InitQueue(Q); 256 | if(T==NULL) 257 | return true; 258 | EnQueue(Q,T); 259 | BTREE p; 260 | while(!isEmpty(Q)){ 261 | DeQueue(Q,p); 262 | if(p->lchild&&p->rchild){ 263 | EnQueue(Q,p->lchild); 264 | EnQueue(Q,p->rchild); 265 | } 266 | else if(p->rchild&&!p->lchild) 267 | return false; 268 | else{ 269 | if(p->lchild&&!p->rchild) 270 | EnQueue(Q,p->lchild); 271 | while(!isEmpty(Q)){ 272 | DeQueue(Q,p); 273 | if(p->lchild||p->rchild) 274 | return false; 275 | } 276 | } 277 | } 278 | return true; 279 | } 280 | void find(BTREE T,int k) 281 | { 282 | if(T==NULL) return; 283 | count[k]++; 284 | if(MAXlchild,k+1); 287 | find(T->rchild,k+1); 288 | } 289 | int TreeMaxWidthre(BTREE T){ 290 | find(T,0); 291 | return MAX; 292 | } 293 | int TreeMaxWidth(BTREE T){ 294 | BTREE p; 295 | int level[Max];//保存层次节点 296 | Queue Q; 297 | InitQueue(Q); 298 | EnQueue(Q,T); 299 | level[Q.rear] = 1;//根节点层次 300 | int max = 0; 301 | while(!isEmpty(Q)){ 302 | DeQueue(Q,p); 303 | int k = level[Q.front]; 304 | if(p->lchild){ 305 | EnQueue(Q,p->lchild); 306 | level[Q.rear] = k+1;//新一层 307 | } 308 | if(p->rchild){ 309 | EnQueue(Q,p->rchild); 310 | level[Q.rear] = k+1;//新一层 311 | } 312 | int i=0; 313 | k = 1; 314 | while(i<=Q.rear){ 315 | int n = 0; 316 | while(i<=Q.rear&&level[i] == k){ 317 | n++; 318 | i++; 319 | } 320 | k = level[i]; 321 | if(n>max){ 322 | max = n; 323 | } 324 | } 325 | } 326 | return max; 327 | } 328 | int main() { 329 | BTREE T; 330 | cout<<"input a tree:"< 2 | #include 3 | using namespace std; 4 | const int Max = 100000; 5 | typedef struct BSTNode *BSTree; 6 | struct BSTNode{ 7 | int key; 8 | BSTree lchild; 9 | BSTree rchild; 10 | }; 11 | //BST的插入 12 | int BST_insert(BSTree &T,int k){ 13 | if(T==NULL){//第一次插入,创建根节点 14 | T = new BSTNode; 15 | T->key = k; 16 | T->lchild = NULL; 17 | T->rchild = NULL; 18 | return 1;//创建成功,返回1 19 | } 20 | else if(k==T->key) 21 | return 0;//存在相同关键字,插入失败 22 | else if(kkey) 23 | return BST_insert(T->lchild,k); 24 | else 25 | return BST_insert(T->rchild,k); 26 | 27 | } 28 | //BST的查找 29 | BSTree BST_search(BSTree &T,int k,int &count){ 30 | BSTree p = T; 31 | while(p){ 32 | count++; 33 | if(k==p->key) 34 | return p; 35 | if(k>p->key) 36 | p = p->rchild; 37 | else 38 | p = p->lchild; 39 | } 40 | return p;//查找不到,返回空 41 | } 42 | //BST的删除 43 | //该函数用于待删除节点既有左子树又有右子树的情况 44 | //返回直接后继的关键字并删除直接后继 45 | int deletemin(BSTree &T){ 46 | int tmp; 47 | BSTree p; 48 | if(T->lchild==NULL){ 49 | p = T; 50 | tmp = T->key; 51 | T = T->rchild; 52 | delete p; 53 | return tmp; 54 | }//T就是最小 55 | else return deletemin(T->lchild);//最小结点一定在左子树上 56 | } 57 | void BST_delete(BSTree &T,int k){ 58 | if(T!=NULL){ 59 | if(kkey) 60 | BST_delete(T->lchild,k); 61 | else if(k>T->key) 62 | BST_delete(T->rchild,k); 63 | else//等于了 64 | if(T->rchild==NULL)//右子树为空 65 | T=T->lchild; 66 | else if(T->lchild==NULL)//左子树为空 67 | T=T->rchild; 68 | else 69 | T->key = deletemin(T->rchild); 70 | } 71 | } 72 | //BST的排序 73 | void visit(BSTree T){ 74 | cout<key<<" "; 75 | } 76 | //中序遍历 77 | void BST_sort(BSTree &T){ 78 | if(T!=NULL){ 79 | BST_sort(T->lchild); 80 | visit(T); 81 | BST_sort(T->rchild); 82 | } 83 | } 84 | //BST的建立 85 | void BST_creat(BSTree &T,int data[],int n){ 86 | T=NULL; 87 | for(int i = 0;i>in){ 99 | // data[i++] = in; 100 | // } 101 | // BST_creat(T,data,i); 102 | // int k; 103 | // cout<<"Insert a number:"<>k; 105 | // BST_insert(T,k); 106 | // BST_sort(T); 107 | // cout<>k; 110 | // BST_delete(T,k); 111 | // BST_sort(T); 112 | // } 113 | // void test02(){ 114 | // BSTree T; 115 | // ifstream infile; 116 | // infile.open("inputdata1.txt"); 117 | // int in; //临时存放单个数据 118 | // int data[Max]; 119 | // int i = 0;//记录数据数量 120 | // while(infile>>in){ 121 | // data[i++] = in; 122 | // } 123 | // BST_creat(T,data,i); 124 | // int k; 125 | // cout<<"Search a number:"<>k; 127 | // BSTree p = BST_search(T,k); 128 | // cout<key; 129 | // } 130 | void TimesOfSearch(BSTree &T,int data[],int i){ 131 | BST_creat(T,data,i); 132 | int counts = 0; 133 | int j = 0;//查找成功的数的个数 134 | int countf = 0; 135 | int k = 0;//查找失败的数的个数 136 | for (int i = 0; i <= 2048; ++i){ 137 | if(i%2){//这是能查找成功的 138 | j++; 139 | BST_search(T,i,counts); 140 | } 141 | else{//这是不能查找成功的 142 | k++; 143 | BST_search(T,i,countf); 144 | } 145 | } 146 | double ASLs = (double)counts/j; 147 | double ASLf = (double)countf/k; 148 | cout<<"查找成功的平均查找长度为:"<>in){ 161 | data[i++] = in; 162 | } 163 | infile.close(); 164 | TimesOfSearch(T,data,i); 165 | 166 | BSTree S; 167 | ifstream infile2; 168 | infile2.open("inputdata2.txt"); 169 | int in2; //临时存放单个数据 170 | int data2[Max]; 171 | int j = 0;//记录数据数量 172 | while(infile2>>in2){ 173 | data2[j++] = in2; 174 | } 175 | infile.close(); 176 | TimesOfSearch(S,data2,j); 177 | BST_sort(S); 178 | } -------------------------------------------------------------------------------- /作业5 查找结构与排序方法/代码及报告/BinarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int Max = 10000; 4 | using namespace std; 5 | int Binary_Search(int a[],int n,int key,int& count){ 6 | int low = 0,high = n,mid; 7 | while(low<=high){ 8 | mid = (low+high)>>1; 9 | count++; 10 | if(a[mid] == key) 11 | return mid; 12 | else if(a[mid]>key) 13 | high = mid-1; 14 | else 15 | low = mid+1; 16 | } 17 | return -1; 18 | } 19 | int main(){ 20 | ifstream infile; 21 | infile.open("inputdata1.txt"); 22 | int in; 23 | int data[Max]; 24 | int count = 0; 25 | while(infile>>in){ 26 | data[count++] = in; 27 | } 28 | int counts = 0; 29 | int j = 0;//查找成功的数的个数 30 | int countf = 0; 31 | int k = 0;//查找失败的数的个数 32 | for (int i = 0; i <= 2048; ++i){ 33 | if(i%2){//这是能查找成功的 34 | j++; 35 | Binary_Search(data,count,i,counts); 36 | } 37 | else{//这是不能查找成功的 38 | k++; 39 | Binary_Search(data,count,i,countf); 40 | } 41 | } 42 | double ASLs = (double)counts/j; 43 | double ASLf = (double)countf/k; 44 | cout<<"查找成功的平均查找长度为:"< 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | const int Max = 2048; 7 | int main() { 8 | ofstream outfile("inputdata1.txt"); 9 | int data[Max]; 10 | int j = 0; 11 | for (int i = 0; i <= Max; ++i) { 12 | if (i % 2) { 13 | data[j++] = i; 14 | outfile << i << endl; 15 | } 16 | } 17 | outfile.close(); 18 | ofstream outfile1("inputdata2.txt"); 19 | srand((int)time(NULL)); 20 | for (int i = 0; i < 1000000; i++) 21 | { 22 | int pose = rand() % j; 23 | swap(data[pose],data[j-pose-1]);//随即交换 24 | swap(data[pose+1],data[j-pose-1]); 25 | } 26 | while(j--){ 27 | outfile1< 2 | using namespace std; 3 | int main(){ 4 | freopen("test.in","r",stdin); 5 | string s; 6 | cin>>s; 7 | int ans = 0; 8 | for(int i = 0;i<(int)s.length()-2;i++) 9 | for(int j = i+1;j<(int)s.length()-1;j++) 10 | for(int k = j+1;k<(int)s.length();k++) 11 | if(s[i]=='Q'&&s[j]=='A'&&s[k]=='Q') 12 | ans++; 13 | cout< 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | #define ASC 128 9 | #define m 2*ASC-1//2n-1个节点 10 | //第一位,编码总数total(char型) 11 | //下total位,字符(char型) 12 | //下total-1位,哈夫曼树(int型) 13 | int total; 14 | long long count; 15 | typedef struct { 16 | double weight; 17 | int lchild; 18 | int rchild; 19 | int parent; 20 | } HTNode; 21 | typedef struct { 22 | char ch;//字符 23 | double freq;//字符频率 24 | char code[ASC];//哈夫曼编码 25 | } Orchar; 26 | HTNode HTree[m]; 27 | Orchar Or[ASC]; 28 | int main(){ 29 | ifstream bfile("CompressedFile.huffman",ios::binary); 30 | ofstream file("OutputText.txt"); 31 | if(!bfile){ 32 | cout<<"Failed To Open The Compressed File!"<>total; 37 | bfile>>noskipws;//设置读取空白符 38 | //各字符 39 | for (int i = 0; i < total; ++i){ 40 | bfile>>Or[i].ch; 41 | } 42 | //哈夫曼树节点 43 | for (int i = total; i < 2 * total - 1; ++i)//0-n-1为字符 44 | { 45 | unsigned char p1,p2; 46 | bfile>>p1>>p2; 47 | HTree[i].lchild = (int)p1; 48 | HTree[i].rchild = (int)p2; 49 | } 50 | //字符数 51 | bfile>>count; 52 | cout<<"读入成功!"<> b1; 56 | int i = 0; 57 | int j = 2*total-2; 58 | int ccount = 0; 59 | while(ccount> (7 - i)) & 1)) 61 | j = HTree[j].rchild; 62 | else 63 | j = HTree[j].lchild; 64 | ++i; 65 | if (j < total) 66 | { 67 | file << Or[j].ch; 68 | ccount++; 69 | j = 2 * total - 2; 70 | } 71 | if (i == 8) 72 | { 73 | i = 0; 74 | bfile>>b1; 75 | } 76 | } 77 | bfile.close(); 78 | file.close(); 79 | cout << "解压成功!" << endl; 80 | } -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/Huffman_Char.cpp: -------------------------------------------------------------------------------- 1 | //基于字符编码 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | #define ASC 128 11 | #define m 2*ASC-1//2n-1个节点 12 | 13 | int totalch;//字符种类数 14 | long long countch;//总字符数 15 | 16 | typedef struct { 17 | double weight; 18 | int lchild; 19 | int rchild; 20 | int parent; 21 | } HTNode; 22 | 23 | typedef struct { 24 | char ch;//字符 25 | double freq;//字符频率 26 | char code[m];//哈夫曼编码 27 | } Orchar; 28 | 29 | 30 | HTNode HTree[m]; 31 | Orchar Or[ASC];//记录各字符信息 32 | 33 | //分字符读文件,返回总字符数 34 | long long ReadFile(string &text) { 35 | ifstream file("InputText.txt"); 36 | if (!file) { 37 | cout << "Failed To Open The File!" << endl; 38 | return 0; 39 | } 40 | int List[ASC] = {0};//频数 41 | char ch; 42 | long long i = 0;//总字符数 43 | int total = 0;//字符种类数 44 | while (file.get(ch)) { 45 | text += ch;//测试 46 | List[(int)ch]++; 47 | i++; 48 | } 49 | file.close(); 50 | int p = 0; 51 | for (int k = 0; k < ASC; ++k) { 52 | if (List[k]) { 53 | total++; 54 | Or[p].ch = k; 55 | Or[p].freq = (double)List[k] / i; 56 | p++; 57 | } 58 | } 59 | totalch = total;//字符种类数 60 | return i; 61 | } 62 | //初始化结点值 63 | void InitHTree() { 64 | for (int i = 0; i < totalch; ++i) 65 | HTree[i].weight = Or[i].freq; 66 | for (int i = 0; i < m; ++i) 67 | { 68 | HTree[i].parent = -1; 69 | HTree[i].lchild = -1; 70 | HTree[i].rchild = -1; 71 | } 72 | } 73 | //选取两个最小数 74 | void SelectMin(int n, int& p1, int& p2) { 75 | int i, j; 76 | for (i = 0; i < n; ++i) { 77 | if (HTree[i].parent == -1) { 78 | p1 = i; 79 | break; 80 | } 81 | } 82 | for (j = i + 1; j < n; ++j) { 83 | if (HTree[j].parent == -1) { 84 | p2 = j; 85 | break; 86 | } 87 | } 88 | for (i = p1; i < n; ++i) { 89 | if ((HTree[p1].weight > HTree[i].weight) && (HTree[i].parent == -1) && (p2 != i)) 90 | p1 = i; 91 | } 92 | for (j = p2; j < n; ++j) { 93 | if ((HTree[p2].weight > HTree[j].weight) && (HTree[j].parent == -1) && (p1 != j)) 94 | p2 = j; 95 | } 96 | } 97 | //创建数 98 | void CreatHT() { 99 | int i, p1, p2; 100 | InitHTree(); 101 | int n = totalch; 102 | for (i = n; i < 2 * n - 1; ++i)//0-n-1为字符 103 | { 104 | SelectMin(i, p1, p2); 105 | HTree[p1].parent = HTree[p2].parent = i; 106 | HTree[i].lchild = p1; 107 | HTree[i].rchild = p2; 108 | HTree[i].weight = HTree[p1].weight + HTree[p2].weight; 109 | } 110 | 111 | } 112 | //编码 113 | void CharSetHuffmanEncoding() { 114 | int c, p, i; //cp分别为孩子和双亲的位置 115 | char cd[ASC + 1]; //临时存放编码 116 | cd[totalch] = '\0'; 117 | int start;//编码在cd中的位置 118 | for (i = 0; i < totalch; ++i) { 119 | start = totalch; 120 | c = i; 121 | while ((p = HTree[c].parent) >= 0) { 122 | cd[--start] = (HTree[p].lchild == c) ? '0' : '1'; //左0右1 123 | c = p;//上溯 124 | } 125 | strcpy(Or[i].code, &cd[start]); 126 | } 127 | } 128 | //输出二进制文件 129 | void HuffmanConpress() { 130 | ifstream file("InputText.txt"); 131 | char ch; 132 | if (!file) { 133 | cout << "Failed To Open The Original Text!" << endl; 134 | } 135 | ofstream bfile; 136 | bfile.open("CompressedFile.huffman", ios::binary); 137 | if (!bfile) { 138 | cout << "Failed To Open The Compressed Text!" << endl; 139 | } 140 | //解释数据 141 | bfile << totalch; 142 | for (int i = 0; i < totalch; i++) 143 | bfile << Or[i].ch; 144 | for (int i = totalch; i < 2 * totalch - 1; ++i) 145 | bfile << (unsigned char)HTree[i].lchild << (unsigned char)HTree[i].rchild; //左右结点 146 | bfile << countch; 147 | int t;//查找 148 | unsigned char bin = 0;//1字节 149 | int index; 150 | int bitindex = 0; 151 | while (file.get(ch)) { 152 | for (t = 0; t < totalch; t++) { 153 | if (Or[t].ch == ch) //查码 154 | break; 155 | } 156 | for (index = 0; Or[t].code[index]; ++index) { 157 | if (Or[t].code[index] == '0') 158 | bin = bin << 1; 159 | else 160 | bin = (bin << 1) + 1; 161 | 162 | bitindex++; 163 | if (bitindex == 8) { 164 | bfile << bin; 165 | bitindex = 0; 166 | bin = 0; 167 | } 168 | 169 | } 170 | } 171 | if (bitindex) { //最后不足8位 172 | bin = bin << (8 - bitindex); 173 | bfile << bin << (unsigned char)bitindex; 174 | } 175 | file.close(); 176 | bfile.close(); 177 | 178 | } 179 | //输出压缩信息 180 | void CompressInformantion(string text) { 181 | double Inbits = 8 * countch; 182 | double Outbits = 0; 183 | for (int i = 0; i < countch; i++) { 184 | int t; 185 | int j; 186 | for (t = 0; t < totalch; t++) { 187 | if (Or[t].ch == text[i]) //查码 188 | break; 189 | } 190 | for (j = 0; Or[t].code[j]; j++); 191 | Outbits += j; 192 | } 193 | cout << "理论压缩率为:" << (double)Outbits / Inbits * 100 << "%" << endl; 194 | struct _stat In, Out; 195 | _stat("InputText.txt", &In); 196 | _stat("CompressedFile.huffman", &Out); 197 | double Inbitst = In.st_size; 198 | double Outbitst = Out.st_size; 199 | cout << "实际压缩率为:" << (double)Outbitst / Inbitst * 100 << "%" << endl; 200 | } 201 | 202 | void test1() { 203 | string text;//文件读入字符串中 204 | countch = ReadFile(text); 205 | CreatHT(); 206 | CharSetHuffmanEncoding(); 207 | cout<<"--------------------基于字符的压缩--------------------"< 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #define MaxWord 10000//最大单词种类数 12 | #define mw 2*MaxWord-1 13 | 14 | int totalword;//单词种类数 15 | long long countword;//总单词数 16 | 17 | typedef struct { 18 | double weight; 19 | int lchild; 20 | int rchild; 21 | int parent; 22 | } HTNode; 23 | 24 | typedef struct { 25 | string word;//单词 26 | double freq;//单词频率 27 | char code[MaxWord];//哈夫曼编码 28 | } Orword; 29 | 30 | HTNode HTreew[mw]; 31 | Orword Ow[MaxWord]; 32 | 33 | //堆结构 34 | //最小堆 35 | typedef struct { 36 | int num;//与Orword对应 37 | double weight; 38 | } ElemType; 39 | typedef struct{ 40 | ElemType data[mw]; 41 | int n; 42 | }heap; 43 | //堆功能 44 | void InitHeap(heap& heap);//初始化 45 | bool isHeapEmpty(heap heap);//判空 46 | bool HeapFull(heap heap);//判满 47 | void HeapInsert(heap& heap, ElemType m);//插入 48 | ElemType HeapDeleteMin(heap& heap, int&num);//删除最小 49 | 50 | void Initheap(heap& heap){ 51 | heap.n = 0; 52 | } 53 | bool isHeapEmpty(heap heap){ 54 | return (!heap.n); 55 | } 56 | bool HeapFull(heap heap){ 57 | return (heap.n == MaxWord - 1); 58 | } 59 | 60 | void HeapInsert(heap& heap, ElemType m){ 61 | int i; 62 | if (!HeapFull(heap)) 63 | { 64 | i = ++heap.n; 65 | while ((i != 1) && (m.weight < heap.data[i / 2].weight)) 66 | { 67 | heap.data[i] = heap.data[i / 2]; 68 | i /= 2; 69 | } 70 | } 71 | heap.data[i].num = m.num; 72 | heap.data[i].weight = m.weight; 73 | } 74 | ElemType HeapDeleteMin(heap& heap){ 75 | int parent = 1, child = 2; 76 | ElemType tmp,elem; 77 | if (!isHeapEmpty(heap)) 78 | { 79 | elem = heap.data[1]; 80 | tmp = heap.data[heap.n--]; 81 | while (child <= heap.n) 82 | { 83 | if ((child < heap.n) && (heap.data[child].weight > heap.data[child + 1].weight)) 84 | ++child; 85 | if (tmp.weight <= heap.data[child].weight) 86 | break; 87 | heap.data[parent] = heap.data[child]; 88 | parent = child; 89 | child *= 2; 90 | } 91 | } 92 | heap.data[parent] = tmp; 93 | return elem; 94 | } 95 | void CreatHeap(heap& heap){ 96 | Initheap(heap); 97 | for(int i = 0;i= 'A' && t[i] <= 'z') {//如果这个字符为字母,开始记录 124 | while (t[i] >= 'A' && t[i] <= 'z') { 125 | w = w + t[i]; 126 | i++; 127 | } 128 | j++; 129 | } 130 | else { 131 | w = t[i];//标点,直接记录 132 | i++; 133 | j++; 134 | } 135 | int index = 0; 136 | int flag = 0; 137 | while (Ow[index].word != "") { 138 | if (Ow[index].word == w) { 139 | Ow[index].freq++;//freq在这里为频数 140 | flag = 1; 141 | break; 142 | } 143 | else { 144 | index++; 145 | } 146 | } 147 | if (flag == 0) { 148 | totalword++; 149 | Ow[index].word = w; 150 | Ow[index].freq++; 151 | } 152 | } 153 | file.close(); 154 | return j; 155 | } 156 | //利用堆找两个最小值 157 | void SelectMinword(heap& heap,int& p1, int& p2) { 158 | p1 = HeapDeleteMin(heap).num; 159 | p2 = HeapDeleteMin(heap).num; 160 | } 161 | // void SelectMinword(int n, int& p1, int& p2) { 162 | // int i, j; 163 | // for (i = 0; i < n; ++i) { 164 | // if (HTreew[i].parent == -1) { 165 | // p1 = i; 166 | // break; 167 | // } 168 | // } 169 | // for (j = i + 1; j < n; ++j) { 170 | // if (HTreew[j].parent == -1) { 171 | // p2 = j; 172 | // break; 173 | // } 174 | // } 175 | // for (i = p1; i < n; ++i) { 176 | // if ((HTreew[p1].weight > HTreew[i].weight) && (HTreew[i].parent == -1) && (p2 != i)) 177 | // p1 = i; 178 | // } 179 | // for (j = p2; j < n; ++j) { 180 | // if ((HTreew[p2].weight > HTreew[j].weight) && (HTreew[j].parent == -1) && (p1 != j)) 181 | // p2 = j; 182 | // } 183 | // } 184 | 185 | //初始化结点值 186 | void InitHTreeword() { 187 | for (int i = 0; i < totalword; ++i) 188 | HTreew[i].weight = Ow[i].freq; 189 | for (int i = 0; i < mw; ++i) 190 | { 191 | HTreew[i].parent = -1; 192 | HTreew[i].lchild = -1; 193 | HTreew[i].rchild = -1; 194 | } 195 | } 196 | //创建树 197 | void CreatHTword() { 198 | int i, p1, p2; 199 | InitHTreeword(); 200 | heap heap; 201 | CreatHeap(heap); 202 | int n = totalword; 203 | for (i = n; i < 2 * n - 1; ++i)//0-n-1为字符 204 | { 205 | SelectMinword(heap,p1, p2); 206 | HTreew[p1].parent = HTreew[p2].parent = i; 207 | HTreew[i].lchild = p1; 208 | HTreew[i].rchild = p2; 209 | HTreew[i].weight = HTreew[p1].weight + HTreew[p2].weight; 210 | ElemType m; 211 | m.num = i; 212 | m.weight = HTreew[i].weight; 213 | HeapInsert(heap,m); 214 | } 215 | } 216 | //编码 217 | void WordSetHuffmanEncoding() { 218 | int c, p, i; //cp分别为孩子和双亲的位置 219 | char cd[MaxWord + 1]; //临时存放编码 220 | cd[totalword] = '\0'; 221 | int start;//编码在cd中的位置 222 | for (i = 0; i < totalword; ++i) { 223 | start = totalword; 224 | c = i; 225 | while ((p = HTreew[c].parent) >= 0) { 226 | cd[--start] = (HTreew[p].lchild == c) ? '0' : '1'; //左0右1 227 | c = p;//上溯 228 | } 229 | strcpy(Ow[i].code, &cd[start]); 230 | } 231 | } 232 | //计算频率 233 | void ConvertFreq(){ 234 | for(int i = 0;Ow[i].word!="";i++){ 235 | Ow[i].freq = (double)Ow[i].freq/countword; 236 | } 237 | } 238 | void wordHuffmanConpress(){ 239 | ifstream file("InputText.txt"); 240 | char ch; 241 | if (!file) { 242 | cout << "Failed To Open The Original Text!" << endl; 243 | } 244 | ofstream bfile; 245 | bfile.open("CompressedFile.huffman", ios::binary); 246 | if (!bfile) { 247 | cout << "Failed To Open The Compressed Text!" << endl; 248 | } 249 | //无解释数据 250 | int t;//查找 251 | unsigned char bin = 0;//1字节 252 | int index; 253 | int bitindex = 0; 254 | string s; 255 | while (file.get(ch)) { 256 | s += ch; 257 | } 258 | string w = ""; 259 | int i = 0; 260 | while (s[i]) { 261 | w = ""; 262 | if (s[i] >= 'A' && s[i] <= 'z') {//如果这个字符为字母,开始记录 263 | while (s[i] >= 'A' && s[i] <= 'z') { 264 | w = w + s[i]; 265 | i++; 266 | } 267 | } 268 | else { 269 | w = s[i];//标点,直接记录 270 | i++; 271 | } 272 | for (t = 0; t < totalword; t++) { 273 | if (Ow[t].word == w) //查码 274 | break; 275 | } 276 | for (index = 0; Ow[t].code[index]; ++index) { 277 | if (Ow[t].code[index] == '0') 278 | bin = bin << 1; 279 | else 280 | bin = (bin << 1) + 1; 281 | 282 | bitindex++; 283 | if (bitindex == 8) { 284 | bfile << bin; 285 | bitindex = 0; 286 | bin = 0; 287 | } 288 | 289 | } 290 | } 291 | if (bitindex) { //最后不足8位 292 | bin = bin << (8 - bitindex); 293 | bfile << bin << (unsigned char)bitindex; 294 | } 295 | file.close(); 296 | bfile.close(); 297 | } 298 | void CompressInformantionword(){ 299 | struct _stat In, Out; 300 | _stat("InputText.txt", &In); 301 | _stat("CompressedFile.huffman", &Out); 302 | double Inbitst = In.st_size; 303 | double Outbitst = Out.st_size; 304 | cout << "实际压缩率为:" << (double)Outbitst / Inbitst * 100 << "%" << endl; 305 | } 306 | void test2() { 307 | countword = ReadFileWord(); 308 | ConvertFreq(); 309 | CreatHTword(); 310 | WordSetHuffmanEncoding(); 311 | cout<<"--------------------基于单词的压缩--------------------"<>noskipws;//设置读取空白符 338 | unsigned char b1; 339 | bfile >> b1; 340 | int i = 0; 341 | int j = 2*totalword-2; 342 | int ccount = 0; 343 | while(ccount> (7 - i)) & 1)) 345 | j = HTreew[j].rchild; 346 | else 347 | j = HTreew[j].lchild; 348 | ++i; 349 | if (j < totalword) 350 | { 351 | file << Ow[j].word; 352 | ccount++; 353 | j = 2 * totalword - 2; 354 | } 355 | if (i == 8) 356 | { 357 | i = 0; 358 | bfile>>b1; 359 | } 360 | } 361 | bfile.close(); 362 | file.close(); 363 | cout << "解压成功!" << endl; 364 | } 365 | int main() { 366 | test2(); 367 | DeCompressWord(); 368 | return 0; 369 | } 370 | -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/InputText.txt: -------------------------------------------------------------------------------- 1 | Assistant director Dave Halls did not know the prop contained live ammunition and indicated it was unloaded by shouting "cold gun!", the records say. 2 | 3 | Cinematographer Halyna Hutchins was fatally shot in the chest in Thursday's incident on the set of the film Rust. 4 | 5 | Director Joel Souza, who was standing behind her, was wounded. 6 | 7 | The 48-year-old received emergency treatment for a shoulder injury and was later released from hospital. 8 | 9 | I have a dream 10 | I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. 11 | 12 | Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of bad captivity. 13 | But one hundred years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. 14 | 15 | Further details of the police investigation were released on Friday when a search warrant was filed at a court in Santa Fe, New Mexico. 16 | 17 | It noted that Baldwin's blood-stained outfit was taken as evidence along with the gun. Ammunition and other prop weapons were also taken from the set by police. 18 | 19 | The 63-year-old actor was questioned by law enforcement, but no-one has been charged over the incident. 20 | 21 | Earlier on Friday, Baldwin - who was the star and producer of the film - said he was "fully co-operating" with the Santa Fe County Sheriff's Office. 22 | 23 | "My heart is broken for her husband, their son, and all who knew and loved Halyna," he wrote on Twitter. 24 | 25 | "There are no words to convey my shock and sadness regarding the tragic accident that took the life of Halyna Hutchins, a wife, mother and deeply admired colleague of ours." 26 | 27 | Ms Hutchins, 42, was from Ukraine and grew up on a Soviet military base in the Arctic Circle. She studied journalism in Kyiv, and film in Los Angeles, and was named a "rising star" by the American Cinematographer magazine in 2019. 28 | 29 | She was the director of photography for the 2020 action film Archenemy, directed by Adam Egypt Mortimer. 30 | 31 | According to the Los Angeles Times, about half a dozen members of the camera crew on Rust walked out hours before the tragedy after protesting over working conditions on the set at the Bonanza Creek Ranch near Santa Fe. 32 | 33 | The union members had reportedly complained that they were promised hotel rooms in Santa Fe, but once filming of the Western began they were required to drive 50 miles (80km) from Albuquerque every morning. 34 | -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/K_Huffman.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验2 树形结构及其应用/代码及报告/K_Huffman.cpp -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/OutputText.txt: -------------------------------------------------------------------------------- 1 | Assistant director Dave Halls did not know the prop contained live ammunition and indicated it was unloaded by shouting "cold gun!", the records say. 2 | 3 | Cinematographer Halyna Hutchins was fatally shot in the chest in Thursday's incident on the set of the film Rust. 4 | 5 | Director Joel Souza, who was standing behind her, was wounded. 6 | 7 | The 48-year-old received emergency treatment for a shoulder injury and was later released from hospital. 8 | 9 | I have a dream 10 | I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. 11 | 12 | Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of bad captivity. 13 | But one hundred years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. 14 | 15 | Further details of the police investigation were released on Friday when a search warrant was filed at a court in Santa Fe, New Mexico. 16 | 17 | It noted that Baldwin's blood-stained outfit was taken as evidence along with the gun. Ammunition and other prop weapons were also taken from the set by police. 18 | 19 | The 63-year-old actor was questioned by law enforcement, but no-one has been charged over the incident. 20 | 21 | Earlier on Friday, Baldwin - who was the star and producer of the film - said he was "fully co-operating" with the Santa Fe County Sheriff's Office. 22 | 23 | "My heart is broken for her husband, their son, and all who knew and loved Halyna," he wrote on Twitter. 24 | 25 | "There are no words to convey my shock and sadness regarding the tragic accident that took the life of Halyna Hutchins, a wife, mother and deeply admired colleague of ours." 26 | 27 | Ms Hutchins, 42, was from Ukraine and grew up on a Soviet military base in the Arctic Circle. She studied journalism in Kyiv, and film in Los Angeles, and was named a "rising star" by the American Cinematographer magazine in 2019. 28 | 29 | She was the director of photography for the 2020 action film Archenemy, directed by Adam Egypt Mortimer. 30 | 31 | According to the Los Angeles Times, about half a dozen members of the camera crew on Rust walked out hours before the tragedy after protesting over working conditions on the set at the Bonanza Creek Ranch near Santa Fe. 32 | 33 | The union members had reportedly complained that they were promised hotel rooms in Santa Fe, but once filming of the Western began they were required to drive 50 miles (80km) from Albuquerque every morning. 34 | -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/test.in: -------------------------------------------------------------------------------- 1 | QAQAQYSYIOIWIN -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验2 树形结构及其应用/代码及报告/实验报告.doc -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/测试数据和结果数据.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验2 树形结构及其应用/代码及报告/测试数据和结果数据.docx -------------------------------------------------------------------------------- /实验2 树形结构及其应用/代码及报告/测试文本集.txt: -------------------------------------------------------------------------------- 1 | Assistant director Dave Halls did not know the prop contained live ammunition and indicated it was unloaded by shouting "cold gun!", the records say. 2 | 3 | Cinematographer Halyna Hutchins was fatally shot in the chest in Thursday's incident on the set of the film Rust. 4 | 5 | Director Joel Souza, who was standing behind her, was wounded. 6 | 7 | The 48-year-old received emergency treatment for a shoulder injury and was later released from hospital. 8 | 9 | I have a dream 10 | I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. 11 | 12 | Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of bad captivity. 13 | But one hundred years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. 14 | 15 | Further details of the police investigation were released on Friday when a search warrant was filed at a court in Santa Fe, New Mexico. 16 | 17 | It noted that Baldwin's blood-stained outfit was taken as evidence along with the gun. Ammunition and other prop weapons were also taken from the set by police. 18 | 19 | The 63-year-old actor was questioned by law enforcement, but no-one has been charged over the incident. 20 | 21 | Earlier on Friday, Baldwin - who was the star and producer of the film - said he was "fully co-operating" with the Santa Fe County Sheriff's Office. 22 | 23 | "My heart is broken for her husband, their son, and all who knew and loved Halyna," he wrote on Twitter. 24 | 25 | "There are no words to convey my shock and sadness regarding the tragic accident that took the life of Halyna Hutchins, a wife, mother and deeply admired colleague of ours." 26 | 27 | Ms Hutchins, 42, was from Ukraine and grew up on a Soviet military base in the Arctic Circle. She studied journalism in Kyiv, and film in Los Angeles, and was named a "rising star" by the American Cinematographer magazine in 2019. 28 | 29 | She was the director of photography for the 2020 action film Archenemy, directed by Adam Egypt Mortimer. 30 | 31 | According to the Los Angeles Times, about half a dozen members of the camera crew on Rust walked out hours before the tragedy after protesting over working conditions on the set at the Bonanza Creek Ranch near Santa Fe. 32 | 33 | The union members had reportedly complained that they were promised hotel rooms in Santa Fe, but once filming of the Western began they were required to drive 50 miles (80km) from Albuquerque every morning. 34 | 35 | I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of bad captivity. But one hundred years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. One hundred years later, the Negro lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the Negro is still languished in the corners of American society and finds himself an exile in his own land. And so we've come here today to dramatize a shameful condition. In a sense we've come to our nation's capital to cash a check. When the architects of our republic wrote the magnificent words of the Constitution and the Declaration of Independence, they were signing a promissory note to which every American was to fall heir. This note was a promise that all men, yes, black men as well as white men, would be guaranteed the "unalienable Rights" of "Life, Liberty and the pursuit of Happiness." It is obvious today that America has defaulted on this promissory note, insofar as her citizens of color are concerned. Instead of honoring this sacred obligation, America has given the Negro people a bad check, a check which has come back marked "insufficient funds." But we refuse to believe that the bank of justice is bankrupt. We refuse to believe that there are insufficient funds in the great vaults of opportunity of this nation. And so, we've come to cash this check, a check that will give us upon demand the riches of freedom and the security of justice. We have also come to this hallowed spot to remind America of the fierce urgency of Now. This is no time to engage in the luxury of cooling off or to take the tranquilizing drug of gradualism. Now is the time to make real the promises of democracy. Now is the time to rise from the dark and desolate valley of segregation to the sunlit path of racial justice. Now is the time to lift our nation from the quicksands of racial injustice to the solid rock of brotherhood. Now is the time to make justice a reality for all of God's children. It would be fatal for the nation to overlook the urgency of the moment. This sweltering summer of the Negro's legitimate discontent will not pass until there is an invigorating autumn of freedom and equality. Nineteen sixty-three is not an end, but a beginning. And those who hope that the Negro needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual. And there will be neither rest nor tranquility in America until the Negro is granted his citizenship rights. The whirlwinds of revolt will continue to shake the foundations of our nation until the bright day of justice emerges. But there is something that I must say to my people, who stand on the warm threshold which leads into the palace of justice: In the process of gaining our rightful place, we must not be guilty of wrongful deeds. Let us not seek to satisfy our thirst for freedom by drinking from the cup of bitterness and hatred. We must forever conduct our struggle on the high plane of dignity and discipline. We must not allow our creative protest to degenerate into physical violence. Again and again, we must rise to the majestic heights of meeting physical force with soul force. The marvelous new militancy which has engulfed the Negro community must not lead us to a distrust of all white people, for many of our white brothers, as evidenced by their presence here today, have come to realize that their destiny is tied up with our destiny. And they have come to realize that their freedom is inextricably bound to our freedom. We cannot walk alone. And as we walk, we must make the pledge that we shall always march ahead. We cannot turn back. There are those who are asking the devotees of civil rights, "When will you be satisfied?" We can never be satisfied as long as the Negro is the victim of the unspeakable horrors of police brutality. We can never be satisfied as long as our bodies, heavy with the fatigue of travel, cannot gain lodging in the motels of the highways and the hotels of the cities. We cannot be satisfied as long as the Negro's basic mobility is from a smaller ghetto to a larger one. We can never be satisfied as long as our children are stripped of their selfhood and robbed of their dignity by signs stating "for whites only." We cannot be satisfied as long as a Negro in Mississippi cannot vote and a Negro in New York believes he has nothing for which to vote. No, no, we are not satisfied, and we will not be satisfied until "justice rolls down like waters, and righteousness like a mighty stream." I am not unmindful that some of you have come here out of great trials and tribulations. Some of you have come fresh from narrow jail cells. And some of you have come from areas where your quest -- quest for freedom left you battered by the storms of persecution and staggered by the winds of police brutality. You have been the veterans of creative suffering. Continue to work with the faith that unearned suffering is redemptive. Go back to Mississippi, go back to Alabama, go back to South Carolina, go back to Georgia, go back to Louisiana, go back to the slums and ghettos of our northern cities, knowing that somehow this situation can and will be changed. Let us not wallow in the valley of despair, I say to you today, my friends. And so even though we face the difficulties of today and tomorrow, I still have a dream. It is a dream deeply rooted in the American dream. I have a dream that one day this nation will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident, that all men are created equal." I have a dream that one day on the red hills of Georgia, the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood. I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice. I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. I have a dream today! I have a dream that one day, down in Alabama, with its vicious racists, with its governor having his lips dripping with the words of "interposition" and "nullification" -- one day right there in Alabama little black boys and black girls will be able to join hands with little white boys and white girls as sisters and brothers. I have a dream today! I have a dream that one day every valley shall be exalted, and every hill and mountain shall be made low, the rough places will be made plain, and the crooked places will be made straight; "and the glory of the Lord shall be revealed and all flesh shall see it together." This is our hope, and this is the faith that I go back to the South with. With this faith, we will be able to hew out of the mountain of despair a stone of hope. With this faith, we will be able to transform the jangling discords of our nation into a beautiful symphony of brotherhood. With this faith, we will be able to work together, to pray together, to struggle together, to go to jail together, to stand up for freedom together, knowing that we will be free one day. And this will be the day -- this will be the day when all of God's children will be able to sing with new meaning: My country 'tis of thee, sweet land of liberty, of thee I sing. Land where my fathers died, land of the Pilgrim's pride, From every mountainside, let freedom ring! And if America is to be a great nation, this must become true. And so let freedom ring from the prodigious hilltops of New Hampshire. Let freedom ring from the mighty mountains of New York. Let freedom ring from the heightening Alleghenies of Pennsylvania. Let freedom ring from the snow-capped Rockies of Colorado. Let freedom ring from the curvaceous slopes of California. But not only that: Let freedom ring from Stone Mountain of Georgia. Let freedom ring from Lookout Mountain of Tennessee. Let freedom ring from every hill and molehill of Mississippi. From every mountainside, let freedom ring. And when this happens, when we allow freedom ring, when we let it ring from every village and every hamlet, from every state and every city, we will be able to speed up that day when all of God's children, black men and white men, Jews and Gentiles, Protestants and Catholics, will be able to join hands and sing in the words of the old Negro spiritual: Free at last! Free at last! Thank God Almighty, we are free at last! 36 | 37 | Meanwhile, the BBC has obtained a document showing which crew members were listed as scheduled to be on set that day. 38 | 39 | It names a head armourer, the crew member responsible for checking firearms. Hannah Gutierrez Reed is in her twenties and, according to the LA Times, had recently worked in this role for the first time. 40 | 41 | It is one of the dirtiest countries per head of population and a massive global supplier of fossil fuels. Unusually for a rich nation, it also still burns coal for most of its electricity. 42 | 43 | Australia's 2030 emissions target - a 26% cut on 2005 levels - is half the US and UK benchmarks. 44 | 45 | Canberra has also resisted joining the two-thirds of countries who have pledged net zero emissions by 2050. 46 | 47 | And instead of phasing out coal - the worst fossil fuel - it's committed to digging for more. 48 | 49 | So it's no surprise that Australia is being viewed as a "bad guy" going into the COP26 global climate talks in Glasgow, analysts say. 50 | 51 | Prime Minister Scott Morrison's government is under huge pressure to do more. 52 | 53 | Mining has helped drive Australia's economy for decades, and coal remains the country's second-biggest export. 54 | 55 | Only Indonesia sells more coal than Australia globally. 56 | 57 | The government often credits coal for much of the country's wealth, but many analysts argue this is overblown. 58 | 59 | Coal exports totalled A$55bn (29bn; $40bn) last year, but most of this wealth was kept by mining companies. Less than a tenth went to Australia directly - that's about 1% of national revenue. 60 | 61 | The coal workforce of 40,000 is about half the size of McDonald's in Australia. But coal jobs do sustain some rural communities. -------------------------------------------------------------------------------- /实验2 树形结构及其应用/实验2 树形结构及其应用.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验2 树形结构及其应用/实验2 树形结构及其应用.pdf -------------------------------------------------------------------------------- /实验3 图形结构及其应用/代码及报告/Graph.txt: -------------------------------------------------------------------------------- 1 | 11 22 2 | 0 1 2 3 4 5 6 7 8 9 10 3 | 0 1 2 4 | 0 2 5 5 | 1 0 3 6 | 1 2 1 7 | 1 3 3 8 | 2 3 3 9 | 2 4 4 10 | 3 4 1 11 | 3 5 7 12 | 3 6 4 13 | 4 5 1 14 | 4 7 4 15 | 4 8 6 16 | 5 1 10 17 | 5 9 2 18 | 6 5 2 19 | 6 9 1 20 | 7 8 1 21 | 7 9 2 22 | 8 5 7 23 | 9 8 1 24 | 10 8 3 -------------------------------------------------------------------------------- /实验3 图形结构及其应用/代码及报告/实验报告.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验3 图形结构及其应用/代码及报告/实验报告.doc -------------------------------------------------------------------------------- /实验3 图形结构及其应用/代码及报告/最短路径算法.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验3 图形结构及其应用/代码及报告/最短路径算法.cpp -------------------------------------------------------------------------------- /实验3 图形结构及其应用/代码及报告/测试数据与结果数据.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验3 图形结构及其应用/代码及报告/测试数据与结果数据.docx -------------------------------------------------------------------------------- /实验3 图形结构及其应用/代码及报告/测试数据图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验3 图形结构及其应用/代码及报告/测试数据图.jpg -------------------------------------------------------------------------------- /实验3 图形结构及其应用/实验3 图型结构及其应用.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcxain/HIT-Data-Structure/b808d64628b33cb5b59d6a622fd3537fa2b4ac62/实验3 图形结构及其应用/实验3 图型结构及其应用.pdf --------------------------------------------------------------------------------