A. Sort
Element There are many cases where we want elements to have a sequence in the way specified, for example, from small to large. There are a number of ways to sort, and we'll explain one of them.
Example:
Order the elements in the above array, from small to large. This can't be figured out, before talking about a two-digit comparison that gets a large number.
Listen to a little explanation of the video, suddenly have a train of thought, angle standard 0 and the angle of 1 after comparison, the size of the element has been replaced, and then continue to the angle of 0 and the remaining angle of the elements of the comparison, the final guarantee that the element in the angle mark 0 is the smallest of all the corners. Then repeat the angle Mark 1 and the elements in the back corner of the comparison, and then a minimum value, so reciprocating. When sorting here, one thing to note is that the corners and spaces are always from 0 to 5, and if ordered, the elements inside are constantly changing positions . Do not rigidly think that the angle of the element is fixed, the variable wants to get the data of the element, only need to label its angle to the variable, as for the angle label changes, then give the change of the angle label can not affect the assignment, while the array storage is still those values, no change.
→ The example in this section has evolved from a size comparison of two numbers. This also proves that there is always a pattern behind the phenomenon, and nothing can be seen out of thin air.
→ In the application of arrays, both the element and the angular label are important and need attention.
For the above example, the number of corner marks is clear, but also relatively few, in the writing of the source code is relatively good writing. Extension, if the number of data in the array is more, how to get a small to large sort? That might take advantage of the automatic function of the looping structure. Why do you say that? I currently do not see the video of the problem solving source code, however, my idea is that five corner-labeled element sorting issues, I set five independent loop structure comparison. Five independent, reusability is not good, should put it together.
→→ need to iterate through an array, what does it mean to iterate over an array? Traversal seems to be the manipulation of all elements.
Big trap small Circle thought.
Their own problem-solving process
Video Problem Solving
Java-preliminary Understanding-fifth-arrays-common operations-select sort