Monday, March 21, 2011

lecture

void print(char *s)
{
if (*s == NULL)
return;
cout << *s;
print(s + 1);
}

void print(int a[], int start, int end)
{
if (start > end)
return;
cout << a[start] << ", ";
print(a, start + 1, end);
}

main()
{
int X[5] = {1, 4, 5, 7};
print(X, 0, 3);
}

HW:
take the map of letters to bitstrings and use it to encode
your text

The cat in the hat

step 1: make one big string of 1s and 0s. concatenation.
say, a for loop through "The cat in the hat", each time, concatenating a[i] to previous string.

step 2: divide strlen by 8 to find size to allocate
byte buffer = new byte[properSize]

step 3: loop through each 8 bits to create a byte. assign
the byte to the proper slot. as you read each "bit", if it is "0", bitshift to left and dont do anything. if it is "1", bitshift to left and bitwise or it with 1.

"0110110"

byte b = 0;
if current is 0:
 b = (b << 1)
else if current is 1:
 b = (b << 1) | 1;

after 8 bits, write it into position buffer[i] and increment i;

going forward, what do we want to store?
a) huffman tree
b) size
c) buffer

we will want to serialize it.
but not yet.

No comments:

Post a Comment