0

I know that the code sorts a list of temperatures numerically but i cant get my head round what it does in detail, as in line by line.

public void sortnumerically()
	{
		for (int i = 0; i < temperatures.size() - 1; i++)
		{
			int min = i;

			for (int current = i + 1; current < temperatures.size(); current++)
			{
				if (temperatures.get(current) < temperatures.get(min))
				{
					min = current;
				}

			}

			temperatures.set(i, temperatures.get(min));
			
			cities.set(i, cities.get(min));

			temperatures.set(min, temperatures.get(i));
			
			cities.set(min, cities.get(i));
		}
4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by verruckt24
0

Put this chunk of code in a main inside class, compile it, then run it, add a System.out.println() after every statement to trace what is happening to your variables.
Thats the most optimal way of finding out rather than asking people for a line by line explanation.

0

better yet ... make sure you have the complete code

for instance: what is cities? performing actions on something you don't know ...
can be tricky :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.