Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include "HuffmanCode.h"
  2. #include <iostream>
  3. #include <cstddef>
  4. #include <string>
  5.  
  6. Huffman::Huffman(): weight(0) {
  7. // this->root = Node(0);
  8.  
  9. }
  10.  
  11. // Huffman::Huffman Huffman &a, Huffman &b) {
  12. // this->weight = a.weight + b.weight;
  13. // this->height = (a.height > b.height) ? a.height : b.height + 1;
  14. // this->root = Node(0);
  15.  
  16. // }
  17.  
  18.  
  19. void Huffman::createHuffmanTree(PriorityQueue<Huffman> &p) {
  20. while (!p.secondEmpty()) {
  21. Huffman* parent = new Huffman;
  22. Huffman temp1 = p.peek();
  23. p.dequeue();
  24. Huffman temp2 = p.peek();
  25. p.dequeue();
  26. p.enqueue(*parent);
  27. }
  28. }
  29.  
  30. void Huffman::printHuffman(freqNode* parent) {
  31. // printHuffman(parent->getLeft());
  32. // std::cout << parent->getWeight() << std::endl;
  33. // printHuffman(parent->getRighty());
  34. }
  35.  
  36.  
  37.  
  38. void Huffman::setWeight(int x) {
  39. weight = x;
  40. }
  41.  
  42. void Huffman::setHeight(int x) {
  43. height = x;
  44. }
  45.  
  46. int Huffman::getWeight() {
  47. return weight;
  48. }
  49.  
  50. int Huffman::getHeight() {
  51. return height;
  52. }
  53.  
  54. /*Huffman Huffman::createHuffmanNode(freqNode* p) {
  55. Huffman new_Huffman;
  56. new_Huffman.setWeight(p->getWeight());
  57. new_Huffman.setChar(p->getCharacter());
  58. return new_Huffman;
  59. }*/
  60.  
  61. void Huffman::setChar(char x) {
  62. Char = x;
  63. }
  64.  
  65. char Huffman::getchar() {
  66. return Char;
  67. }
  68.  
  69. // void Huffman::Node::setLeft(Huffman::Node* left) {
  70. // this->left = left;
  71. // }
  72.  
  73. // void Huffman::Node::setRight(Huffman::Node* right) {
  74. // this->right = right;
  75. // }
  76.  
  77. bool Huffman::operator > (Huffman &r) {
  78. return (weight > r.getWeight());
  79. }
  80.  
  81. bool Huffman::operator < (Huffman &r) {
  82. return (weight < r.getWeight());
  83. }
  84.  
  85. bool Huffman::operator >= (Huffman &r) {
  86. return (weight >= r.getWeight());
  87. }
  88.  
  89. bool Huffman::operator <= (Huffman &r) {
  90. return (weight <= r.getWeight());
  91. }
  92.  
  93. std::ostream &operator<<(std::ostream &os, Huffman &r) {
  94. os << "Weight: " << r.getWeight() << " Character: " << r.getchar() << std::endl;
  95. return os;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement