program untuk sorting data menggunakan algoritma seleksi
atau sering disebut selection sort#include "stdio.h"
main()
#include "conio.h"
{
int data[10] = {22,2,5,7,9,0,32,34,37,56},x;
for (int index=0;index<=9;index++)
{
printf("%3d",data[index]);
}
for (int index=0;index<9;index++)
{
int x=index;
for(int index2=index+1;index2<=9;index2++)
{
if(data[x]>data[index2])
{
x=index2;
}
}
int trans=data[index];
data[index]=data[x];
data[x]=trans;
}
printf("\n\n");
for (int index=0;index<=9;index++)
{
printf("%3d",data[index]);
}
getch();
}
Monday, February 18, 2008
Selection Sort (C)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment