File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Possible error in finding min/max inside of a LinkedList<LinkedList> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Possible error in finding min/max inside of a LinkedList<LinkedList>" Watch "Possible error in finding min/max inside of a LinkedList<LinkedList>" New topic
Author

Possible error in finding min/max inside of a LinkedList<LinkedList>

Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Hi,
I have a linked list, containing objects with a linked list object inside. I have to find the min/max values in the "table's" each "column". Those values then are stored in a MinMax object and added to a linked list. I have a hunch that this piece of code is not finding the values correctly. Maybe there is a better way?
Thanks in advance!

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Janis Strautins wrote: I have a linked list, containing objects with a linked list object inside.


How have you declared your LinkedList intervalList?


~ Mansukh
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Yes I have, it's a global variable.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I asked "How"? Show me how is your LinkedList declared. I know you have done it.
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Oops, sorry. Like this:

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8419
    
  23

Janis Strautins wrote:Yes I have, it's a global variable.

OK, why don't you show us ALL the relevant code (but only the bits that relate to THIS function). It's a bit difficult to make an assessment without all the information.

However, just off the top of my head, I don't like the sound of a "global variable". max() is a function, not a value.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Ok, I tried to find all the code. The KMeans class gets the table when it is created. After that, MinMax() is called, which finds the min/max value in each column. A call to CreateCentroids, which uses the intervalList to generate numbers in the interval. When i print the values from the centroid creation, the min value is 0, although there is no such value in the table. I'm thinking of just creating two linked lists, one for the min and one for the max values. This seemed such an easy task, but as usual, the easier it seems, the harder it is..





Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8419
    
  23

Janis Strautins wrote:Ok, I tried to find all the code.

That's not really what I asked for. I said all relevant code; but never mind...

It sounds to me like you're dealing with far too much. Forget your matrix for the moment, and just try to write a method that returns the minimum or maximum value from a simple List (or array). You can always refine it later on to deal with "columns".

And before you write another line of Java code, sit down with a pencil and paper and write out the solution in English.

You will never code your way out of a jam.

Winston
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Winston Gutkowski wrote:
And before you write another line of Java code, sit down with a pencil and paper and write out the solution in English.

You will never code your way out of a jam.

Winston


That is perhaps the best advice you ever gave me, or for that matter anybody, Winston.
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Thanks for the advice But i prefer to write down the solution in my native tongue.
Anyway, used 2 lists for the values and everything is working like a charm, thanks for the help^^
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Janis Strautins wrote:Thanks for the advice But i prefer to write down the solution in my native tongue.
Anyway, used 2 lists for the values and everything is working like a charm, thanks for the help^^


Dutch? Or Swede?
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
You guessed wrong, Latvian
While this topic is still alive, i have a question regarding hierarchical clustering - after the algorithm has completed, how should i find the center of each of the clusters? In k-means it's easy, because i have the centers from the very beginning, but in the case divisive and agglomerative algorithms, i don't. That is neede so i can calculate the average/sum distance to the center of the cluster. Any ideas?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

It would be better if you created a separate thread for this. Let's not mix up things, shall we.
Janis Strautins
Greenhorn

Joined: Dec 12, 2012
Posts: 18
Very well, let the admin close this one^^
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8419
    
  23

Janis Strautins wrote:Very well, let the admin close this one^^

Actually, I can't (mind you, I'm only a "lesser" admin). But you can.

Winston
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Can I suggest people stick to Java questions and let us worry about whether to split threads or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible error in finding min/max inside of a LinkedList<LinkedList>