From ec5e167ee8f63c1eb0830deae11fbb7642f6a658 Mon Sep 17 00:00:00 2001 From: Devansh786 Date: Tue, 15 Jun 2021 07:13:43 +0530 Subject: [PATCH] hello --- 14_2013306_Devansh_Rawat/q1.txt | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 14_2013306_Devansh_Rawat/q1.txt diff --git a/14_2013306_Devansh_Rawat/q1.txt b/14_2013306_Devansh_Rawat/q1.txt new file mode 100644 index 0000000..4a4ff04 --- /dev/null +++ b/14_2013306_Devansh_Rawat/q1.txt @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ll long long + +#define MIN(a, b) a < b ? a : b +#define MAX(a, b) a > b ? a : b + +using namespace std; + +int readline(char *str) { + int i = 0; + char ch; + while((ch = getchar()) != '\n') { + str[i++] = ch; + } + str[i] = '\0'; + return i; +} + +struct node { + int freq; + char data; + struct node * left; + struct node * right; +}; + +struct node * new_node(int freq, char data) { + struct node * t = (struct node *) calloc(1, sizeof(struct node)); + t->data = data; + t->freq = freq; + return t; +} + +void decode_huff(struct node * root, string s) { + struct node * p = root; + for(int i = 0 ; s[i]; i++) { + + if(s[i] == '0') { + p = p->left; + } + else { + p = p->right; + } + + if(p->left == NULL && p->right == NULL) { + printf("%c", p->data); + p = root; + } + } + printf("\n"); \ No newline at end of file