Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions 14_2013306_Devansh_Rawat/q1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <iostream>
#include <list>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#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");