HTML5¼¼Êõ

Êý¾Ý½á¹¹Í¼ÎĽâÎöÖ®£º¹þ·òÂüÊ÷Óë¹þ·òÂü±àÂëÏê½â¼°C++Ä£°åʵÏÖ - melonstreet(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-02-12 14:00 ÎÒÒªÆÀÂÛ( )

/*´òÓ¡¹þ·òÂüÊ÷*/ template typename T void HuffmanT::print(HuffmanNodeT* pnode){ if (pnode != nullptr ){cout µ±Ç°½áµã£º pnode-key . ; if (pnode-lchild != nullptr )cout ËüµÄ×óº¢×Ó½ÚµãΪ£º pnode-lchild-

/*´òÓ¡¹þ·òÂüÊ÷*/ template<typename T> void Huffman<T>::print(HuffmanNode<T>* pnode) { if (pnode != nullptr) { cout << "µ±Ç°½áµã£º" << pnode->key<<"."; if (pnode->lchild != nullptr) cout << "ËüµÄ×óº¢×Ó½ÚµãΪ£º" << pnode->lchild->key << "."; else cout << "ËüûÓÐ×óº¢×Ó."; if (pnode->rchild != nullptr) cout << "ËüµÄÓÒº¢×Ó½ÚµãΪ£º" << pnode->rchild->key << "."; else cout << "ËüûÓÐÓÒº¢×Ó."; cout << endl; print(pnode->lchild); print(pnode->rchild); } };

3.5 ¹þ·òÂüÊ÷´úÂë²âÊÔ

ÎÒÃǹ¹½¨ÉÏͼÖеĹþ·òÂüÊ÷£¬ËüµÄËĸöȨֵ·Ö±ðΪ{10£¬20£¬30£¬40}£º
²âÊÔ´úÂ룺

int _tmain(int argc, _TCHAR* argv[]) { Huffman<int> huff; int a[] = { 10,20,30,40 }; huff.creat(a, 4); //¹¹½¨Ò»¿Ã¹þ·òÂüÊ÷ huff.print(); //´òÓ¡½Úµã¼ä¹Øϵ getchar(); return 0; }

²âÊÔ½á¹û£º

µ±Ç°½áµã£º100.ËüµÄ×óº¢×Ó½ÚµãΪ£º40.ËüµÄÓÒº¢×Ó½ÚµãΪ£º60. µ±Ç°½áµã£º40.ËüûÓÐ×óº¢×Ó.ËüûÓÐÓÒº¢×Ó. µ±Ç°½áµã£º60.ËüµÄ×óº¢×Ó½ÚµãΪ£º30.ËüµÄÓÒº¢×Ó½ÚµãΪ£º30. µ±Ç°½áµã£º30.ËüûÓÐ×óº¢×Ó.ËüûÓÐÓÒº¢×Ó. µ±Ç°½áµã£º30.ËüµÄ×óº¢×Ó½ÚµãΪ£º10.ËüµÄÓÒº¢×Ó½ÚµãΪ£º20. µ±Ç°½áµã£º10.ËüûÓÐ×óº¢×Ó.ËüûÓÐÓÒº¢×Ó. µ±Ç°½áµã£º20.ËüûÓÐ×óº¢×Ó.ËüûÓÐÓÒº¢×Ó.

¸ù¾Ý½Úµã¹Øϵ¿ÉÒÔ»­³öÈç϶þ²æÊ÷£¬ÕýÊÇÉÏÃæÎÒÃǹ¹½¨µÄ¹þ·òÂüÊ÷¡£

4. ÔÙ¿´¹þ·òÂü±àÂë

Ϊ{10£¬20£¬30£¬40}ÕâËĸöȨֵ¹¹½¨Á˹þ·òÂü±àÂëºó£¬ÎÒÃÇ¿ÉÒÔÓÉÈçϹæÔò»ñµÃËüÃǵĹþ·òÂü±àÂ룺

  • ´Ó¸ù½Úµãµ½Ã¿Ò»¸öÒ¶×Ó½ÚµãµÄ·¾¶ÉÏ£¬×ó·ÖÖ§¼ÇΪ0£¬ÓÒ·ÖÖ§¼ÇΪ1£¬½«ÕâЩ0Óë1Á¬ÆðÀ´¼´ÎªÒ¶×Ó½ÚµãµÄ¹þ·òÂü±àÂë¡£ÈçÏÂͼ£º
  • £¨×Öĸ£©È¨Öµ ±àÂë

    10 100

    20 101

    30 11

    40 0

    Óɴ˿ɼû£¬³öÏÖƵÂÊÔ½¸ßµÄ×Öĸ£¨Ò²¼´È¨ÖµÔ½´ó£©£¬Æä±àÂëÔ½¶Ì¡£Õâ±ãʹ±àÂëÖ®ºóµÄ×Ö·û´®µÄƽ¾ù³¤¶È¡¢ÆÚÍûÖµ½µµÍ£¬´Ó¶ø´ïµ½ÎÞËðѹËõÊý¾ÝµÄÄ¿µÄ¡£

    5. ¹þ·òÂüÊ÷ÍêÕû´úÂë

    ¹þ·òÂüÊ÷ÍêÕû´úÂ룺https://github.com/huanzheWu/Data-Structure/blob/master/Huffman/Huffman/Huffman.h
    ¸ü¶àÊý¾Ý½á¹¹C++ʵÏÖ´úÂ룺https://github.com/huanzheWu/Data-Structure

    Ô­´´ÎÄÕ£¬×ªÔØÇë×¢Ã÷³ö´¦£º

    ¡¡

    1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

    Ïà¹ØÎÄÕÂ
    • URL½âÎö - ÃîÒôÌìÅ®

      URL½âÎö - ÃîÒôÌìÅ®

      2017-03-27 16:02

    • ¿ªÔ´µÄ.NET¶¨Ê±ÈÎÎñ×é¼þHangfire½âÎö - ÅíÔó0902

      ¿ªÔ´µÄ.NET¶¨Ê±ÈÎÎñ×é¼þHangfire½âÎö - ÅíÔó0902

      2017-03-22 13:00

    • ¿çƽ̨µÄ.NETÓʼþЭÒéMailKit×é¼þ½âÎö - ÅíÔó0902

      ¿çƽ̨µÄ.NETÓʼþЭÒéMailKit×é¼þ½âÎö - ÅíÔó0902

      2017-03-17 13:01

    • ÌÚѶÔÆÊý¾Ý¿âÍŶӣºSQL Server Êý¾Ý¼ÓÃܹ¦ÄܽâÎö - ÌÚѶÔƼ¼ÊõÉçÇø

      ÌÚѶÔÆÊý¾Ý¿âÍŶӣºSQL Server Êý¾Ý¼ÓÃܹ¦ÄܽâÎö - ÌÚѶÔƼ¼ÊõÉçÇø

      2017-03-17 10:00

    ÍøÓѵãÆÀ
    Ò