Home > Back-end > VS2019 according to trigger a breakpoint
VS2019 according to trigger a breakpoint
Time:09-21
# include & lt; Stdio. H> # include "stdlib. H" # include & lt; Conio. H> # include & lt; String. H>
# define MAXVALUE 10000 # define MAXLEAF 30 # define MAXNODE MAXLEAF * 2-1 Typedef struct { Int weight; Int the parent; Int lchild; Int rchild; } HNode HuffmanTree [MAXNODE];
Typedef struct codenode { Char ch; Deposit/* to */symbols Char * code;/* * to store the corresponding code/ } CodeNode; Typedef CodeNode HuffmanCode [MAXLEAF];
Void CrtHuffmanTree (HuffmanTree& Ht, int w [], int n) { Int I, j, m1, m2, x1, x2, for (i=0; I & lt; 2 * n - 1; I++) {/* ht initialization */ Ht [I]. Weight=0; Ht [I]. Parent=1; Ht [I] lchild=1; Ht [I] rchild=1; } for (i=0; I & lt; n; I++) Ht [I]. [I] weight=w; for (i=0; I & lt; N - 1; I++) {/* and Huffman tree */ M1=m2=MAXVALUE; The x1 x2==0; For (j=0; J & lt; N + I; J++) { If (ht [j]. Journal of weight & lt; M1 & amp; & Ht [j]. Journal of parent==1) { M2 equals m1; X2=x1; X1=j; M1=ht [j]. Journal of weight; } Else if (ht [j]. Journal of weight & lt; M2 & amp; & Ht [j]. Journal of parent==1) { M2=ht [j]. Journal of weight; X2=j; } } /* will * two merged into one KeZi KeZi tree tree/ Ht [x1]. Parent=n + I; Ht [x2]. Parent=n + I; Ht [n + I]. Weight=ht [x1]. Weight + ht [x2]. Weight; Ht [n + I] lchild=x1; Ht [n + I] rchild=x2; } }
/* from leaf nodes to root, reverse search for each leaf node corresponding to the symbol Huffman encoding */ Void CrtHuffmanCode (HuffmanTree ht, HuffmanCode& Hc, int n) { Char * CD; Int I, c, p, start; CD=(char *) malloc (n * sizeof (char));/* to the current workspace allocation */ CD] [n - 1='\ 0'; Printf (" please input in order to be coded character: \ n "); for (i=0; I & lt; n; I++) { Start=n - 1; C=I; P=ht [I] the parent; while (p !=1) { If (ht [p]. Lchild==c) CD [-- start]='0'; The else CD [-- start]='1'; C=p; P=ht [p]. The parent; } Hc [I]. Code=(char *) malloc ((n - start) * sizeof (char));/* for the ith encode spatial distribution */ fflush(stdin); Scanf_s (" % c ", & amp; (hc [I] ch)); Strcpy_s (hc [I] code, 10, & amp; CD (start)); } Free (CD); }
Int main () { HuffmanTree ht. Int a w [MAXLEAF], I, n. HuffmanCode hc. Printf (" please enter the number of leaf nodes: "); Scanf_s (" % d ", & amp; N); Printf (" please input weights in turn: \ n "); for (i=0; I & lt; n; I++) Scanf_s (" % d ", & amp; W [I]); CrtHuffmanTree (ht, w, n); CrtHuffmanCode (ht, hc, n); Printf (" Huffman encoding results for: \ n "); for (i=0; I & lt; n; I++) Printf (" % c, % s \ n ", hc [I] ch, hc [I] code); }
Tried it with dev... Run successfully... Don't know where is wrong... Thank you bosses for help
CodePudding user response:
Copy down ran under no problem ah, vs2019 environment
CodePudding user response:
Application memory is too big, not to come out, the assertion?