<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://fenixdocs.com/skins/common/feed.css?63"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://fenixdocs.com/index.php?action=history&amp;feed=atom&amp;title=Ksort</id>
		<title>Ksort - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://fenixdocs.com/index.php?action=history&amp;feed=atom&amp;title=Ksort"/>
		<link rel="alternate" type="text/html" href="http://fenixdocs.com/index.php?title=Ksort&amp;action=history"/>
		<updated>2026-05-01T08:54:42Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.10.1</generator>

	<entry>
		<id>http://fenixdocs.com/index.php?title=Ksort&amp;diff=2650&amp;oldid=prev</id>
		<title>Sandman at 09:51, 17 July 2007</title>
		<link rel="alternate" type="text/html" href="http://fenixdocs.com/index.php?title=Ksort&amp;diff=2650&amp;oldid=prev"/>
				<updated>2007-07-17T09:51:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table border='0' width='98%' cellpadding='0' cellspacing='4' style=&quot;background-color: white;&quot;&gt;
			&lt;tr&gt;
				&lt;td colspan='2' width='50%' align='center' style=&quot;background-color: white;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' width='50%' align='center' style=&quot;background-color: white;&quot;&gt;Revision as of 09:51, 17 July 2007&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; align=&quot;left&quot;&gt;&lt;strong&gt;Line 3:&lt;/strong&gt;&lt;/td&gt;
&lt;td colspan=&quot;2&quot; align=&quot;left&quot;&gt;&lt;strong&gt;Line 3:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;==Definition==&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;==Definition==&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; font-size: smaller;&quot;&gt;'''&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;STRING&lt;/del&gt;''' ksort ( &amp;lt;'''VARSPACE''' array&amp;gt; , &amp;lt;'''VARSPACE''' sort-variable&amp;gt; , [&amp;lt;'''INT''' datacount&amp;gt;] )&lt;/td&gt;&lt;td&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; font-size: smaller;&quot;&gt;'''&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;INT&lt;/ins&gt;''' ksort ( &amp;lt;'''VARSPACE''' array&amp;gt; , &amp;lt;'''VARSPACE''' sort-variable&amp;gt; , [&amp;lt;'''INT''' datacount&amp;gt;] )&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;Sorts a certain [[array]] according to a sort-variable within the elements and by sorting a certain number of elements. By default the whole array is sorted.&lt;/td&gt;&lt;td&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; font-size: smaller;&quot;&gt;Sorts a certain [[array]] according to a sort-variable within the elements and by sorting a certain number of elements. By default the whole array is sorted.&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Sandman</name></author>	</entry>

	<entry>
		<id>http://fenixdocs.com/index.php?title=Ksort&amp;diff=2648&amp;oldid=prev</id>
		<title>Sandman at 09:42, 17 July 2007</title>
		<link rel="alternate" type="text/html" href="http://fenixdocs.com/index.php?title=Ksort&amp;diff=2648&amp;oldid=prev"/>
				<updated>2007-07-17T09:42:04Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:functions]]&lt;br /&gt;
[[Category:sorting]]&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
'''STRING''' ksort ( &amp;lt;'''VARSPACE''' array&amp;gt; , &amp;lt;'''VARSPACE''' sort-variable&amp;gt; , [&amp;lt;'''INT''' datacount&amp;gt;] )&lt;br /&gt;
&lt;br /&gt;
Sorts a certain [[array]] according to a sort-variable within the elements and by sorting a certain number of elements. By default the whole array is sorted.&lt;br /&gt;
&lt;br /&gt;
If the array elements contain only one variable each or the first one is the sort-variable, [[sort]]() can be used. For more advanced sorting, look at [[quicksort]]().&lt;br /&gt;
&lt;br /&gt;
== Parameters ==&lt;br /&gt;
{| &lt;br /&gt;
| '''VARSPACE''' array || - The [[array]] to be sorted.&lt;br /&gt;
|-&lt;br /&gt;
| '''VARSPACE''' sort-variable || - The variable within each element to be used for the sorting.&lt;br /&gt;
|-&lt;br /&gt;
| ['''INT''' datacount] || - Number of elements to sort.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Returns ==&lt;br /&gt;
'''INT''': Successrate&lt;br /&gt;
{|&lt;br /&gt;
| [[true]] || - Sorting succeeded.&lt;br /&gt;
|-&lt;br /&gt;
| [[false]] || - Sorting failed, probably the type of sort-variable isn't supported.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Program sorting;&lt;br /&gt;
&lt;br /&gt;
Type _player&lt;br /&gt;
    String name;&lt;br /&gt;
    int score;&lt;br /&gt;
End&lt;br /&gt;
&lt;br /&gt;
Const&lt;br /&gt;
    maxplayers = 5;&lt;br /&gt;
Global&lt;br /&gt;
    _player player[maxplayers-1];&lt;br /&gt;
Begin&lt;br /&gt;
&lt;br /&gt;
    // Insert some values&lt;br /&gt;
    player[0].name = &amp;quot;That one bad looking dude&amp;quot;;&lt;br /&gt;
    player[1].name = &amp;quot;Ah pretty lame guy&amp;quot;;&lt;br /&gt;
    player[2].name = &amp;quot;Some cool dude&amp;quot;;&lt;br /&gt;
    player[3].name = &amp;quot;OMG ZOMG guy&amp;quot;;&lt;br /&gt;
    player[4].name = &amp;quot;This person is ok&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    player[0].score = 70;&lt;br /&gt;
    player[1].score = 30;&lt;br /&gt;
    player[2].score = 80;&lt;br /&gt;
    player[3].score = 90;&lt;br /&gt;
    player[4].score = 50;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    // Show array&lt;br /&gt;
    say(&amp;quot;-------------------- unsorted&amp;quot;);&lt;br /&gt;
    for(x=0; x&amp;lt;maxplayers; x++)&lt;br /&gt;
        say(player[x].name + &amp;quot; - &amp;quot; + player[x].score);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
/* Sort by name ( quicksort() can't be used to sort Strings,&lt;br /&gt;
   as a String in Fenix is a pointer to the actual String,&lt;br /&gt;
   so it would sort the pointer addresses */&lt;br /&gt;
&lt;br /&gt;
    // sort()&lt;br /&gt;
    sort(player); // sorts by name because name is the first variable in each element&lt;br /&gt;
&lt;br /&gt;
    // Show array&lt;br /&gt;
    say(&amp;quot;-------------------- name - sort()&amp;quot;);&lt;br /&gt;
    for(x=0; x&amp;lt;maxplayers; x++)&lt;br /&gt;
        say(player[x].name + &amp;quot; - &amp;quot; + player[x].score);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    // ksort()&lt;br /&gt;
    ksort(player,player[0].name,maxplayers);&lt;br /&gt;
&lt;br /&gt;
    // Show array&lt;br /&gt;
    say(&amp;quot;-------------------- name - ksort()&amp;quot;);&lt;br /&gt;
    for(x=0; x&amp;lt;maxplayers; x++)&lt;br /&gt;
        say(player[x].name + &amp;quot; - &amp;quot; + player[x].score);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
/* Sort by score (sort() cannot be used here, because score is not the first variable) */&lt;br /&gt;
&lt;br /&gt;
    // ksort()&lt;br /&gt;
    ksort(player,player[0].score,maxplayers);&lt;br /&gt;
&lt;br /&gt;
    // Show array&lt;br /&gt;
    say(&amp;quot;-------------------- score - ksort()&amp;quot;);&lt;br /&gt;
    for(x=0; x&amp;lt;maxplayers; x++)&lt;br /&gt;
        say(player[x].name + &amp;quot; - &amp;quot; + player[x].score);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    // quicksort()&lt;br /&gt;
    quicksort(&amp;amp;player[0],sizeof(_player),maxplayers,sizeof(String),sizeof(int),0);&lt;br /&gt;
&lt;br /&gt;
    // Show array&lt;br /&gt;
    say(&amp;quot;-------------------- score - quicksort()&amp;quot;);&lt;br /&gt;
    for(x=0; x&amp;lt;maxplayers; x++)&lt;br /&gt;
        say(player[x].name + &amp;quot; - &amp;quot; + player[x].score);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    // Wait until ESC is pressed&lt;br /&gt;
    Repeat&lt;br /&gt;
         frame;&lt;br /&gt;
    Until(key(_esc))&lt;br /&gt;
&lt;br /&gt;
End&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Used in example: [[say]](), [[sort]](), [[ksort]](), [[quicksort]](), [[type]], [[array]], [[pointer]]&lt;/div&gt;</summary>
		<author><name>Sandman</name></author>	</entry>

	</feed>