#Average of linked list node

20 messages · Page 1 of 1 (latest)

lunar flame
#

Hi, does anyone know how to find the average of a linked list node, but the type of the node is the object of another class?

cloud apexBOT
#

This post has been reserved for your question.

Hey @lunar flame! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mint violet
#

nope, going to need a lot more info for that

lunar flame
#

ok give me one sec i'll send my code sorry about that

mint violet
#

don't need code

#

need a proper description of what you're trying to do

#

then we can talk about code

lunar flame
#

ok

#

basically i have a class called rating with a constructor of String reviewerID and int rating. In my other class I have a linked list node that is a type of Rating I am trying to get an average rating from the rating class using the Rating linked list node

mint violet
#

sounds like you want the average of the entire list, not just one node

#

iterate to add to a rolling sum and then divide by the amount of elements, that's how you get an average

lunar flame
#

ok thank you

mint violet
#

(average of a node is illogical. averages are fundamentally over multiple values)

lunar flame
#

yeah my bad i meant how do i find the average of the entire list when it's in the type of an object and not a double or int

mint violet
#

sec

#

brb

lunar flame
#

ok, thank you

mint violet
#

you just add the property you want to get the average of

#

if you're using streams, use map/mapToInt