Rosetta Code:Village Pump/Unknown sorting algorithm: Difference between revisions
Content added Content deleted
(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:...) |
(Applied Template:vptopic) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Vptopic |
|||
⚫ | |||
|topic=Unknown sorting algorithm |
|||
|summary=Question on what sorting algorithm this is. |
|||
⚫ | |||
I just made it, and i don't know his name (Bogosort, Bubble Sort and etc.) |
|||
Take a look at my code: |
Take a look at my code: |
||
Line 59: | Line 63: | ||
} |
} |
||
}</lang> |
}</lang> |
||
: This is effectively a [[selection sort]] (find minimum, put in the right place). --[[User:IanOsgood|IanOsgood]] 02:37, 22 April 2009 (UTC) |
|||
: Thanks for a fast answer ;) --[[User:Guga360|Guga360]] 02:50, 22 April 2009 (UTC) |
Latest revision as of 02:22, 10 November 2010
Unknown sorting algorithm
This is a particular discussion thread among many which consider Rosetta Code.
This is a particular discussion thread among many which consider Rosetta Code.
Summary
Question on what sorting algorithm this is.
Discussion
Someone know what sorting algorithm is this? I just made it, and i don't know his name (Bogosort, Bubble Sort and etc.)
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>
- This is effectively a selection sort (find minimum, put in the right place). --IanOsgood 02:37, 22 April 2009 (UTC)
- Thanks for a fast answer ;) --Guga360 02:50, 22 April 2009 (UTC)