Subscribe Twitter Facebook

Rabu, 01 Mei 2013

Program Sedehana Shell Sorting


Script untuk pengaplikasian shell sorting, check this out.. :

#include <iostream.h>
#include <conio.h>

int main (void)
{
int array [5];
int length = 5;
int i, j,d;
int tmp, flag;

for (i=0; i<length; i++)
{
cout <<"Enter a number : ";
cin >> array [i];
}

d=length;
flag=1;
while (flag || (d>1))
{
flag = 0;
d= (d+1)/2;
for (i= 0; i< (length -d); i++)
{
if (array [i+d] > array [i])
{
tmp = array [i+d];
array [i+d] = array [i];
array [i] = tmp;
flag = 1;
}
}
}
for (i=0; i<5; i++)
{
cout << array [i]<< endl;
   }
   getch();
}

Nanti hasilnya akan menjadi seperti ini :


Silahkan dicoba..

0 komentar:

Posting Komentar