Rosetta Code:Village Pump/Unknown sorting algorithm

Revision as of 02:26, 22 April 2009 by rosettacode>Guga360 (New page: Someone know what sorting algorithm is this? Take a look at my code: <lang python>aunsorted = [6, 2, 7, 8, 3, 1, 10, 5, 4, 9] asorted = [] amin = aunsorted[0] aminindex = 0 while True:...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Someone know what sorting algorithm is this?

Take a look at my code:

<lang python>aunsorted = [6, 2, 7, 8, 3, 1, 10, 5, 4, 9] asorted = []

amin = aunsorted[0] aminindex = 0

while True:

   for i in range(len(aunsorted)):
       if aunsorted[i] < amin:
           amin = aunsorted[i]
           aminindex = i
   del aunsorted[aminindex]
   asorted = asorted + [amin]
   if len(aunsorted) == 0: break
   amin = aunsorted[0]
   aminindex = 0


print asorted</lang>

<lang csharp>using System; using System.Collections.Generic;

public class Program {

   static void Main() {
       List<int> unsorted = new List<int>(new int[] { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 });
       List<int> sorted = new List<int>();
       int min = unsorted[0];
       int minindex = 0;
       while (true) {
           for (int i = 0; i < unsorted.Count; i++) {
               if (unsorted[i] < min) {
                   min = unsorted[i];
                   minindex = i;
               }
           }
           unsorted.RemoveAt(minindex);
           sorted.Add(min);
           if (unsorted.Count == 0) break;
           min = unsorted[0];
           minindex = 0;
       }
       foreach (int i in sorted) {
           Console.WriteLine(i);
       }
   }

}</lang>