For practice, I've been working on a compressor which does the find-repeated-parts, make-dictionary, compress-with-huffman codes thing.
It's not really working.
One of the problems is, for some reason my sorting algorithm drops keywords from the dictionary. I think the problem is in the swap routine, but I'm not sure. ( this routine swaps adjacent keywords, with next being current->next ).
I do have a static keyword * head;
void swap(keyword * current, keyword * next) {
keyword * prev = current->prev;
if (prev){
prev->next = next;
next->prev = prev;
} else { /* no prev - current is head */
head = next;
next->prev = 0;
}
current->prev = next;
current->next = next->next;
next->next = current;
}
Spot anything wrong with this?