Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2005, 12:02 AM   PM User | #1
jakenoble
Regular Coder

 
Join Date: Feb 2004
Location: UK, derby
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
jakenoble is an unknown quantity at this point
Java Method help

Hi All

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

Code:
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:
Code:
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?
Code:
myChain = add(myChain,values[i]

Thanks in advance, jake
jakenoble is offline   Reply With Quote
Old 01-14-2005, 12:46 AM   PM User | #2
cfc
Regular Coder

 
Join Date: Dec 2004
Location: Keswick, Ontario
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
cfc is an unknown quantity at this point
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.
cfc is offline   Reply With Quote
Old 01-14-2005, 10:47 AM   PM User | #3
jakenoble
Regular Coder

 
Join Date: Feb 2004
Location: UK, derby
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
jakenoble is an unknown quantity at this point
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?
jakenoble is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:45 AM.


Advertisement
Log in to turn off these ads.