0% found this document useful (0 votes)
9 views2 pages

Contoh Buble Sort

Uploaded by

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

Contoh Buble Sort

Uploaded by

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

#include <iostream>

int data[10];
int n;

void tampil()
{
for (int i = 0; i < n; i++)
{
std::cout << "[" << data[i] << "] "
}
std::cout << std::endl;
}

int main()
{
std::cout << "ALGORITMA BUBBLE SORT" << std::endl;
std::cout << "----------------------" << std::endl

std::cout << "Masukan Jumlah Data = ";


std::cin >> n;

std::cout << std::endl;

for (int i = 0; i < n; i++)


{
std::cout << "Masukan Data Ke-" << i + 1 << " = "
std::cin >> data[i];
}
std::cout << std::endl;
std::cout << "Proses Bubble Sort" << std::endl;

tampil();

for (int i = 1; i < n; i++)


{

for (int j = n - 1; j >= i; j--)


{
if (data[j] < data[j - 1])
{

int t;
t = data[j - 1];
data[j - 1] = data[j];
data[j] = t;
}
}
tampil()
}
std::cout << std::endl;
return 0;
}

You might also like