• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Janis Strautins
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janis Strautins wrote: I have a linked list, containing objects with a linked list object inside.


How have you declared your LinkedList intervalList?
 
Janis Strautins
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have, it's a global variable.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked "How"? Show me how is your LinkedList declared. I know you have done it.
 
Janis Strautins
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, sorry. Like this:

 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Janis Strautins
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be better if you created a separate thread for this. Let's not mix up things, shall we.
 
Janis Strautins
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very well, let the admin close this one^^
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I suggest people stick to Java questions and let us worry about whether to split threads or not.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic