View Full Version : Java Method help

01-14-2005, 01:02 AM
Hi All

I am having some major problems with a piece of work involving Java.
We have been giving the following:

static int add(int chain, int value)
// here you need to provide the code that adds a new element to the front of the chain
// my solution has four lines ...

return NULL; // this line is only here so you can compile and run the code as is.
} // end of method "add"

We are supposed to simulating the "Heap".

Then later we have this:

static public void main(String args[])

System.out.println("start of program");
int myChain = NULL; // initialise the chain ...
int values [] = {76, 42, 33, 29, 50};

for (int i = 0; i < HEAP_SIZE; i++)
heapArray[i] = new HeapElement();

for (int i = 0; i < 5; i++) {
System.out.println(myChain = add(myChain,values[i]));


System.out.println("end of program");

I need to add the values in the "values" Array into specific random points allocated earlier in the program.

But the bit I am confused about is the "add" method, and the way it is used, specifically, what does this mean?

myChain = add(myChain,values[i]

Thanks in advance, jake

01-14-2005, 01:46 AM
Your code on that line is stating:

My Chain = The Function add() used to concatenate (or whatever add() is doing) My Current Chain and the Next Value to be added to it. Then, print that result to the console (assuming System.out is the console).

The for loop basically iterates over the values and add()s them one-by-one to the chain.

01-14-2005, 11:47 AM
Thanks cfc, I am not a little closer to understanding it.

My next problem thats hurting my brain, is the int myChain, it seems that this int must have both a data value, and a next value, how can an int have two values?

Or am I looking at this in the wrong way?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum