How would I add and subtract elements in an array? I want to add two elements that are in an array, take those elements out of the array, and add in the sum of those two elements into the array (so I take out 2 things from the array and add in one new one).
Here's a little example. Let's say we have the array { 1, 3, 6, 7}. I want to sum up the two lowest (1 and 3) , delete the two lowest from the array (1 and 3), and then put that sum back into the array. So in this case I'd end up with {4,6,7}. If I keep going I'll get {10,7}, then {17}
I've already tried google and the java sun forums to no avail. Any help would be greatly appreciated.
2007-02-24
16:17:28
·
4 answers
·
asked by
Galbadian
2
in
Computers & Internet
➔ Programming & Design
I can't just add up all of the elements because I'm doing Huffman Coding...which means each time I add I need to assign a 0 or 1 to the highest and lowest number.
2007-02-24
16:23:34 ·
update #1