0% found this document useful (0 votes)
13 views

Program Selection Sort

This document describes a selection sort algorithm and provides a C++ program to implement it. The program defines an array of 10 integers, then uses a nested for loop to iterate through the array and swap elements to sort them in ascending order. It inputs sample data, performs the selection sort, and outputs the sorted array. The program finds the minimum value in the unsorted section of the array and swaps it into place.

Uploaded by

Muy Net
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Program Selection Sort

This document describes a selection sort algorithm and provides a C++ program to implement it. The program defines an array of 10 integers, then uses a nested for loop to iterate through the array and swap elements to sort them in ascending order. It inputs sample data, performs the selection sort, and outputs the sorted array. The program finds the minimum value in the unsorted section of the array and swaps it into place.

Uploaded by

Muy Net
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

BPTT2

SELECTION SORT

Oleh :
Gusti Ayu Diah Kartika Dewi

(1205021002/IIIA)

Gede Yuda Putra Aryanto

(1205021008/IIIA)

Putu Dendy Jefriyana

(1205021015/IIIA)

I Gusti Putu Wirama

(1205021019/IIIA)

JURUSAN D3 MANAJEMEN INFORMATIKA


FAKULTAS TEKNIK DAN KEJURUAN
UNIVERSITAS PENDIDIKAN GANESHA
2013

Program Selection Sort


#include <constrea.h>
main()
{
int m,c,temp,i,a[10];

//Input data
clrscr();
a[1] = 4;
a[2] = 8;
a[3] = 5;
a[4] = 9;
a[5] = 6;
a[6] = 2;
a[7] = 7;
a[8] = 5;
a[9] = 9;
a[10] = 5;
//Selection sort
clrscr();
for (i=1; i<=10-1; i++){
m=i;
for (c=i+1; c<=10; c++){
if (a[c] > a[m])
m = c;
}
temp = a[i];
a[i] = a[m];
a[m] = temp;
}
//Hasilnya
cout << "Sebelum di urut : 4 8 5 9 6 2 7 5 9 5\n\n";
cout << "Jadi Hasilnya : ";
for (i=1; i<=10; i++)
cout << a[i] << " ";
getch();
}

Hasil Program

You might also like