[ create a new paste ] login | about

Link: http://codepad.org/TB2vxn96    [ raw code | output | fork ]

C++, pasted on Dec 1:
#include <stdio.h>

void swap(char& c1, char& c2)
 { char _tc = c1; c1 = c2; c2 = _tc; }

int main(int argc, char* argv[])
{
	char str[256] = "asortingexample\0";

	printf("%s\n",str);

	for (int i = 0; str[i] != '\0'; i++)
	{
		int min = i;
		for (int k = i+1; str[k] != '\0'; k++)
			min = (str[k] < str[min]) ? k : min;

		swap(str[i],str[min]);
	}

	printf("%s\n",str);

	return 0;
}


Output:
1
2
asortingexample
aaeegilmnoprstx


Create a new paste based on this one


Comments: