Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HuffmanCode.h"
- #include <iostream>
- #include <cstddef>
- #include <string>
- Huffman::Huffman(): weight(0) {
- // this->root = Node(0);
- }
- // Huffman::Huffman Huffman &a, Huffman &b) {
- // this->weight = a.weight + b.weight;
- // this->height = (a.height > b.height) ? a.height : b.height + 1;
- // this->root = Node(0);
- // }
- void Huffman::createHuffmanTree(PriorityQueue<Huffman> &p) {
- while (!p.secondEmpty()) {
- Huffman* parent = new Huffman;
- Huffman temp1 = p.peek();
- p.dequeue();
- Huffman temp2 = p.peek();
- p.dequeue();
- p.enqueue(*parent);
- }
- }
- void Huffman::printHuffman(freqNode* parent) {
- // printHuffman(parent->getLeft());
- // std::cout << parent->getWeight() << std::endl;
- // printHuffman(parent->getRighty());
- }
- void Huffman::setWeight(int x) {
- weight = x;
- }
- void Huffman::setHeight(int x) {
- height = x;
- }
- int Huffman::getWeight() {
- return weight;
- }
- int Huffman::getHeight() {
- return height;
- }
- /*Huffman Huffman::createHuffmanNode(freqNode* p) {
- Huffman new_Huffman;
- new_Huffman.setWeight(p->getWeight());
- new_Huffman.setChar(p->getCharacter());
- return new_Huffman;
- }*/
- void Huffman::setChar(char x) {
- Char = x;
- }
- char Huffman::getchar() {
- return Char;
- }
- // void Huffman::Node::setLeft(Huffman::Node* left) {
- // this->left = left;
- // }
- // void Huffman::Node::setRight(Huffman::Node* right) {
- // this->right = right;
- // }
- bool Huffman::operator > (Huffman &r) {
- return (weight > r.getWeight());
- }
- bool Huffman::operator < (Huffman &r) {
- return (weight < r.getWeight());
- }
- bool Huffman::operator >= (Huffman &r) {
- return (weight >= r.getWeight());
- }
- bool Huffman::operator <= (Huffman &r) {
- return (weight <= r.getWeight());
- }
- std::ostream &operator<<(std::ostream &os, Huffman &r) {
- os << "Weight: " << r.getWeight() << " Character: " << r.getchar() << std::endl;
- return os;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement