/* Function: writeCodeToStream
 * ---------------------------
 * Writes this symbol code to output stream
 *
 * @param symbCode   stores string of bit-code for some symbol
 */
void writeCodeToStream(string symbolCode, obstream& outfileStream) {
    for (int i = 0; i < symbolCode.length(); i++) {
        if (symbolCode[i] == '1') {
            outfileStream.writeBit(1);
        }else{
            outfileStream.writeBit(0);
        }
    }
}
/* Function: writeCodeToStream
 * ---------------------------
 * Writes this symbol code to output stream
 *
 * @param symbCode   stores string of bit-code for some symbol
 */
void writeCodeToStream(string symbCode, obstream& ofbs) {
    for (int i = 0; i < symbCode.length(); i++) {
        if (symbCode[i] == '1') {
            ofbs.writeBit(1);
        }else{
            ofbs.writeBit(0);
        }
    }
}
/* Function: encodeTreeToFileHeader
 * --------------------------------
 * Encodes tree shape into cypherFile.
 * Makes depth traversing of coding tree, and writes:
 *
 * - 0 - if it's knot at this traverse, without symbols
 *
 * - 1 - if it's leaf at this traverse, without childs.
 *   It is followed by char byte code.
 */
void encodeTreeToFileHeader(Node* node, obstream& outfileStream) {
    /* This node is fork end
     * We should write '1' and char code then */
    if ((node->leftChild == NULL) && (node->rightChild == NULL)) {
        outfileStream.writeBit(1);
        outfileStream.put((node->symbol));
    }else{
        /* This node has childs - we should write just '0' */
        outfileStream.writeBit(0);
        if (node->leftChild != NULL) {
            encodeTreeToFileHeader((node->leftChild), outfileStream);
        }
        if (node->rightChild != NULL) {
            encodeTreeToFileHeader((node->rightChild), outfileStream);
        }
    }
}