# Selection and Insert Sort Coding.pdf

Document Sample

```					                                              SELECTION SORT

#include <stdio.h>
#include <conio.h>
main()
{
int i,j,indexmin,n,temp;
int data[20];
printf ("Berapa data yang akan diurutkan? ");
scanf("%i",&n);

for (i=0;i<n;i++)
{
printf ("Masukkan data ke-%i= ",i+1);
scanf ("%i",&data[i]);
}

for (i=0;i<n-1;i++)
{
indexmin=i;
for (j=i+1;j<n;j++)
{
if (data[j]<data[indexmin]) indexmin=j;
}

if ((data[i])!=(data[indexmin]))
{
temp=data[i];
data[i]=data[indexmin];
data[indexmin]=temp;
}
}

printf ("Setelah Pengurutan\n");
for (i=0;i<n;i++)
{
printf ("Elemen ke-%i= %i \n",i+1,data[i]);
}
getch();
}
INSERTION SORT

#include <stdio.h>
#include <conio.h>
main()
{
int i,j,n,temp;
int data[20];
printf ("Berapa data yang akan diurutkan? ");
scanf("%i",&n);

for (i=0;i<n;i++)
{
printf ("Masukkan data ke-%i= ",i+1);
scanf ("%i",&data[i]);
}

for (i=0;i<n;i++)
{
temp=data[i];
j=i-1;

while ((data[j]>=temp) && (j>0))
{
data[j+1]=data[j];
j=j-1;
}

if (temp>=data[j]) data[j+1]=temp;
else
{
data[j+1]=data[j];
data[j]=temp;
}
}

printf ("Setelah Pengurutan\n");
for (i=0;i<n;i++)
{
printf ("Elemen ke-%i= %i \n",i+1,data[i]);
}
getch();
}

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 13 posted: 2/26/2012 language: Malay pages: 2
Description: document for education