Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pqueue.c"
typedef struct hn {
double w;
int id;
struct hn *left, *right;
ia
} hnode;
char decodifica(hnode *node, char *string, int index){ //string è una sequenza di bit per
un carattere
if (node != NULL) {
er
if(string[index]=='0')
decodifica(node->left,string,index+1);
else
decodifica(node->right,string,index+1);
}
if(index==strlen(string)) return node->id;
gn
}
return node;
In
}
int i;
printf("pq full\n");
fflush(stdout);
while (pq) {
pq = popGPQ(pq, (void **) &node1, &w);
Vi
if (node2) {
w = node1->w + node2->w;
node = buildHnode(w, -1, node1, node2);
pq = pushGPQ(pq, (void *) node, w);
}
//printf ("push %lf + %lf = %lf node\n", node1->w, node2->w, w); fflush(stdout);
}
return node;
}
-1-
C:\Users\domen\Documents\Algoritmi e Strutture Dati\Miei Codici\COMPITI DA STAMPARE\17092013-2.c venerdì 29 gennaio 2016 17:04
void printHnode(unsigned long num, int bitnum, int id) {
int i;
printf("id: %c: ", id);
for (i = bitnum-1; i >=0; i--) {
putchar(((1 << i) & num) == 0 ? '0' : '1');
}
putchar('\n');
}
if (htree == NULL)
ia
return;
if (htree->id >= 0) {
er
}
if (htree->left) {
bitnum++;
codifica <<= 1;
printHtree(htree->left);
gn
codifica >>= 1;
bitnum--;
}
if (htree->right) {
bitnum++;
codifica <<= 1;
ge
codifica |= 1;
printHtree(htree->right);
codifica >>= 1;
bitnum--;
}
}
In
int main() {
double w[5] = { 0.5, 0.1, 0.2, 0.15, 0.05 };
int alphabet[5] = { 'A', 'B', 'C', 'D', 'E' };
hnode *htree = NULL;
printHtree(htree);
//printf("%c\n",decodifica(htree,))
return 0;
}
ve
Vi
-2-