monkey_king 39 Junior Poster

There shouldn't be anything wrong with returning a 2-dim array.
Something like the following should work.

#include <iostream>
#include <string>

std::string **getstring(int x, int y){
  std::string **var = new std::string*[x];
  for (int i=0;i<x;i++)
    var[i]=new std::string[y];
  return var;
}

int main(){
  std::string **tmp = getstring(5,10);
  return 0;
}

This assumes the same number of elements at each line, and you should cleanup the memory.

good luck

monkey_king 39 Junior Poster

I think it depends on what you are doing with the file.
I've found that the FILE, strtok is by far the fastest way of reading in data.
I've been using flat files, (same number of columns in all lines).
On the scale of several gigabytes.

And avoiding the c++ streams was faster.
But I've heard rumors that you can tweak the fstream with a fsetbuf,
that should make it faster.

monkey_king 39 Junior Poster

What is the ordering?
If you want to sort by the most frequent elements first, then you can use the link given to you.

If you are sorting by some other rule,
you should say what rule that is.

monkey_king 39 Junior Poster

You should start by defining the problem itself.

First aff all assume you will only be using ascii symbol.
This way you will only be needing to keep track of 128 diffent kind of charachters.
Make an int array 128 long, initilaize to zero for entire entries


Make a good filereader function,
that reads the file char by char until end of file.
For each char get the ascii value and increment the
intarray[asciival of char] ++;

the int array will then contain a table of occurences of the different chars.
The sum of elements should equal the number of chars read from file.

You say you want the frequenzy, then you just need to divide with the total sum.
But for creating the huffmancode, you dont need the frequnzies just an ordered list.

This should get you started

good luck

monkey_king 39 Junior Poster

Use either valgrind or gdb for finding errors.

compile with -g option
then

gdb ./yourprog
run

or
valgrind ./yourprog

monkey_king 39 Junior Poster

I'm using unix, so I can't look at your source files,
but theres something I don't understand in you code for case2

Your are setting temp->next = null;
which probly mean that you want temp->next->next to be deleted instead of temp.

But your should do it before you set the next to null
something like

temp = temp -> next;
delete temp->next;
temp -> next = NULL;
delete cursor;

I have no idea what your 'curser' is though,
so I might be way of.
I haven't looked at your case3.

monkey_king 39 Junior Poster

whats your platform?

monkey_king 39 Junior Poster

Then show us the line that contains the assignment error.
And maybe even the compile error itself.

monkey_king 39 Junior Poster

Try cutting down your program to just a few lines,
check the compile errors, fix those.
Then you should understand what you did wrong.

monkey_king 39 Junior Poster

It depends on how you matrix is defined as a datastructure.

Sometimes they are defined as one long array.
Then you can just add the array elementwise.

If they are defined as double pointers,
then you should loop through the entire matrices in the sameorder.