From 9ff09c9a28968f695b6e2ab84588cea37a80d77a Mon Sep 17 00:00:00 2001 From: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> Date: Sat, 13 Jan 2024 15:34:52 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E9=80=A0=E5=93=88=E5=A4=AB=E6=9B=BC?= =?UTF-8?q?=E6=A0=91=E5=92=8C=E7=94=9F=E6=88=90=E5=93=88=E5=BC=97=E6=9B=BC?= =?UTF-8?q?=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bala <13452927+rfgsdhshgfh@user.noreply.gitee.com> --- ...7\346\233\274\347\274\226\347\240\201.cpp" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "2224020152/\347\254\254\344\270\203\345\215\225\345\205\203/\346\236\204\351\200\240\345\223\210\345\244\253\346\233\274\346\240\221\345\222\214\347\224\237\346\210\220\345\223\210\345\274\227\346\233\274\347\274\226\347\240\201.cpp" diff --git "a/2224020152/\347\254\254\344\270\203\345\215\225\345\205\203/\346\236\204\351\200\240\345\223\210\345\244\253\346\233\274\346\240\221\345\222\214\347\224\237\346\210\220\345\223\210\345\274\227\346\233\274\347\274\226\347\240\201.cpp" "b/2224020152/\347\254\254\344\270\203\345\215\225\345\205\203/\346\236\204\351\200\240\345\223\210\345\244\253\346\233\274\346\240\221\345\222\214\347\224\237\346\210\220\345\223\210\345\274\227\346\233\274\347\274\226\347\240\201.cpp" new file mode 100644 index 00000000..23628461 --- /dev/null +++ "b/2224020152/\347\254\254\344\270\203\345\215\225\345\205\203/\346\236\204\351\200\240\345\223\210\345\244\253\346\233\274\346\240\221\345\222\214\347\224\237\346\210\220\345\223\210\345\274\227\346\233\274\347\274\226\347\240\201.cpp" @@ -0,0 +1,67 @@ +#include +using namespace std; + +typedef struct { + char data; + double weight; + int parent; + int lchild; + int rchild; +}HTNode; + + +void creatHT(HTNode ht[], int n0) { + double min1, min2; + int lnode, rnode; + + + for (int i = 0; i < 2 * n0 - 1; i++) { + ht[i].parent = ht[i].lchild = ht[i].rchild = -1; + } + + + for (int i = n0; i < 2 * n0 - 1; i++) { + min1 = min2 = 10000; + lnode = rnode = -1; + for (int k = 0; k <= i - 1; k++) { + + + if (ht[k].parent == -1) { + + + if (ht[k].weight < min1) { + min2 = min1; + rnode = lnode; + + min1 = ht[k].weight; + lnode = k; + } + else if(ht[k].weight < min2) { + min2 = ht[k].weight; + rnode = k; + } + } + } + + ht[i].weight = ht[lnode].weight + ht[rnode].weight; + + + ht[i].lchild = lnode; + ht[i].rchild = rnode; + + + ht[lnode].parent = ht[rnode].parent = i; + } +} + +int main() { + HTNode ht[N]; + HCode hcd[N]; + + for (int i = 0; i < 4; i++) { + ht[i].data = 'A' + i; + ht[i].weight = 1 + i; + } + creatHT(ht, 4); + return 0; +} \ No newline at end of file -- Gitee