Thursday, 15 April 2010

sorting - Selection sort only passing once -


Hi is trying to create a selection sort, but it appears to be passed only through the first debug , It displays 3,2,10, 9 5, which is correct, the second debug displays 2.00,0,0,0 and the last one displays 3,0,10,9,5 ,

As you can see it appears only, although once in a while, loop in turn, I am telling that what am I doing?

  int [] list = new int [] {3, 2, 10, 9, 5}; // list int [] ListB = new int [] {0, 0, 0}; // ListB debug Logs (list [0] + "," + list [1] + "," + list [2] + "," + list [3] + "," + list [4] + ","); Int Minimum, Temporary; // new ints for 2 (int external = 0; externally; list.Length-1; external ++) // for the number of ints in the list 0 for loop -1 {min = external; // At least in the list (how many ints) (list [internal] & lt; list [minimum]) // If the list is internal & lt; For external (int intrinsic = 0; internal and lieutenant; list.leng; internal ++) list minimum {min = in; // to minimize the set}} ListB [external] = list [minimum]; // listb external = list minimum list [minimum] = 0; // Set list for at least one dummy value} Debug. Logs (list b [0] + "," + list b [1] + "," + list b [2] + "," + list b [3] + "," + list b [4]); Debug people (list [0] + "," + list [1] + "," + list [2] + "," + list [3] + "," + list [4] + ",");  

When you will perform a loop next to the [min] 0 next time the minimum value Find, as you have a second thing to notice, the first loop should end in the list. Length is the true code

  int [] list = new int [] {3, 2, 10, 9, 5}; // list int [] ListB = new int [] {0, 0, 0}; // ListB debug.log (list [0] + "," + list [1] + "," + list [2] + "," + list [3] + "," + list [4] + ", "); Int Min 0, Temporary; Loops for new entries for // 2 (int external = 0; external & lt; List.Length; external ++) // 0; Number of intents in the list -1 {min = external; // set the minimum from the inner list [inner] and lieutenant; List [minimum]) // If the list is internal & lt; For (int inner = 0; inner & lieut; list; lanag; inner ++) list minimum {minimum = in; // set in minimum}} ListB [external] = list [minimum]; // listb external = list minimum list [minimum] = int.MaxValue; // Set the minimum list for a dummy value} Debug.log (List B [0] + "," + List B [1] + "," + List B [2] + "," + List B [3] ] + "," + List B. [4]); Debug.log (list [0] + "," + list [1] + "," + list [2] + "," + list [3] + "," + list [4] + ",");  

No comments:

Post a Comment