0% found this document useful (0 votes)
33 views1 page

Program Pengurutan Metode Maximum Sort Secara Menaik

This C++ program sorts numbers in ascending order using the maximum sort method. It prompts the user to enter the number of values, reads the values into an array, prints the array before and after sorting, and finds the maximum value in each iteration to swap with the last element.

Uploaded by

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

Program Pengurutan Metode Maximum Sort Secara Menaik

This C++ program sorts numbers in ascending order using the maximum sort method. It prompts the user to enter the number of values, reads the values into an array, prints the array before and after sorting, and finds the maximum value in each iteration to swap with the last element.

Uploaded by

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

/* Program Pengurutan Metode Maximum Sort

Pengurutan Secara Menaik


Nama File : Lat_Sorting_04a */

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int Nilai[20];
int i, j, N, l;
int temp, U, Imaks;
cout<<"Masukkan Banyak Bilangan : ";
cin>>N;
for(i=0; i<N; i++)
{
cout<<"Elemen ke-"<<i<<" : ";
cin>>Nilai[i];
}

//Proses Cetak Sebelum diurutkan


cout<<"\nData sebelum diurut : ";
for(i=0; i<N; i++)
cout<<setw(3)<<Nilai[i];

//Proses Pengurutan
U=N-1;
for(i=0; i<=N-2; i++)
{
Imaks = 0;
for(j=1; j<=U; j++)
{
if(Nilai[j] > Nilai[Imaks])
Imaks = j;
}
temp = Nilai[U];
Nilai[U] = Nilai[Imaks];
Nilai[Imaks] = temp;
U--;
cout<<endl;
for(l=0; l<N; l++)
cout<<setw(3)<<Nilai[l];
}
cout<<"\nData Setelah di urut : ";
for(i=0; i<N; i++)
cout<<setw(3)<<Nilai[i];
getch();
}

You might also like