Metode Pemograman Bubble Sort dengan C++
Metode bubble sort, merupakan metode tersederhana untuk melakukan pengurutan data, tetapi memiliki kinerja yang terburuk untuk data yang besar. Pengurutan dilakukan dengan membandingkan sebuah bilangan dengan seluruh bilangan yang terletak sesudah bilangan tersebut. Penukaran dilakukan kalau suatu kriteria dipenuhi.
Sebagai contoh, terdapat kumpulan seperti berikut.
25 57 48 37 12 92 80 33
Contoh proses pengurutan dengan urut naik ditunjukkan pada gambar

Pengurutan tahap pertama 

Pengurutan tahap kedua 
Jika jumlah data adalah n, maka terjadi n-1 tahap pengurutan. Berarti pada contoh di di atas diperlukan 7 tahap pengurutan. Gambar 11.4 memperlihatkan setelah 7 tahap pengurutan dilakukan.

Keadaan di setiap tahap pengurutan  
Implementasikan pengurutan dengan metode buble sort baik dalam algoritma maupun program
 
Algoritma :
SUBRUTIN bubble_sort(L,n)
Untuk tahap = 1 s/d n-1
Untuk j← 0 s/d n-tahap-1
Jika L[j] > L[j+1] MAKA
// Lakukan penukaran
tmp ←L[j]
L[j] ←L[j+1]
L[j+1] ←tmp
AKHIR – JIKA
AKHIR – UNTUK
AKHIR – UNTUK
AKHIR – SUBRUTIN
Implementasi dalam bahasa pemograman C++
#include <iostream.h>
#include <conio.h>
void tampilkan_larik(int data[], int n)
{
int i;
for(i=0;i<n;i++)
cout<<data[i]<<" ";
cout<<"\n";
}
void buble_sort(int data[],int n)
{
int tahap,j,tmp;
for (tahap=1;tahap<n;tahap++)
{
for (j=0;j<n-tahap;j++)
if (data[j]>data[j+1])
{
//tukarkan
tmp=data[j];
data[j]=data[j+1];
data[j+1]=tmp;
}
cout<<"hasil tahap "<<tahap<<" : ";
tampilkan_larik (data,n);
}
}
int main()
{
const jum_data=8;
int i;
int data[]={25,57,48,37,12,92,80,33};
buble_sort(data, jum_data);
//hasil pengurutan
cout<<endl;
cout<<"Hasil Pengurutan: \n";
tampilkan_larik(data,jum_data);
getch();
}
Gambar Program Setelah Dieksekusi :
 
 
Sebagai contoh, terdapat kumpulan seperti berikut.
25 57 48 37 12 92 80 33
Contoh proses pengurutan dengan urut naik ditunjukkan pada gambar


Jika jumlah data adalah n, maka terjadi n-1 tahap pengurutan. Berarti pada contoh di di atas diperlukan 7 tahap pengurutan. Gambar 11.4 memperlihatkan setelah 7 tahap pengurutan dilakukan.

Implementasikan pengurutan dengan metode buble sort baik dalam algoritma maupun program
Algoritma :
SUBRUTIN bubble_sort(L,n)
Untuk tahap = 1 s/d n-1
Untuk j← 0 s/d n-tahap-1
Jika L[j] > L[j+1] MAKA
// Lakukan penukaran
tmp ←L[j]
L[j] ←L[j+1]
L[j+1] ←tmp
AKHIR – JIKA
AKHIR – UNTUK
AKHIR – UNTUK
AKHIR – SUBRUTIN
Implementasi dalam bahasa pemograman C++
#include <iostream.h>
#include <conio.h>
void tampilkan_larik(int data[], int n)
{
int i;
for(i=0;i<n;i++)
cout<<data[i]<<" ";
cout<<"\n";
}
void buble_sort(int data[],int n)
{
int tahap,j,tmp;
for (tahap=1;tahap<n;tahap++)
{
for (j=0;j<n-tahap;j++)
if (data[j]>data[j+1])
{
//tukarkan
tmp=data[j];
data[j]=data[j+1];
data[j+1]=tmp;
}
cout<<"hasil tahap "<<tahap<<" : ";
tampilkan_larik (data,n);
}
}
int main()
{
const jum_data=8;
int i;
int data[]={25,57,48,37,12,92,80,33};
buble_sort(data, jum_data);
//hasil pengurutan
cout<<endl;
cout<<"Hasil Pengurutan: \n";
tampilkan_larik(data,jum_data);
getch();
}
Gambar Program Setelah Dieksekusi :
 
 
 
 
 
Jadi bingung , yang bener tuh dari besar ke kecil atau kecil ke besar -> Bubble sort ?? :h: :i:
BalasHapusbuble sort itu metode pengurutan,.
BalasHapus..
jadi ga berpengaruh, mau dari besar ke kecil atau kecil ke besar.. (ascending & descending)
.
.kalau sudh pengurutan dengan cara buble sort ya,, buble sort namanya.
.
jadi jangan pusing yah :)
program ini tinggal di copas saja? bisa di copa di blue j? trims maaf newbe
BalasHapuscopas aja....., trus tinggal run :D
BalasHapusI blog often and I truly appreciate your content. This great article has truly
BalasHapuspeaked my interest. I'm going to book mark your blog and keep checking for new details about once a week. I subscribed to your RSS feed as well.
Also visit my blog villa zwembad Te huur duitsland
Very nice article, totally what I needed.
BalasHapusAlso visit my page : vakantiehuis spanje te huur
kalau misalnya dari data yang di input, trus di jadikan array 2 dimensi, trus di jadiin ascending n descending gimana ya?
BalasHapustxq
What's up, I would like to subscribe for this web site to get newest updates, thus where can i do it please help out.
BalasHapusFeel free to visit my site ; vakantiehuis in bodensee
Hey there! I've been following your site for some time now and finally got the courage to go ahead and give you a shout out from Houston Tx! Just wanted to say keep up the good work!
BalasHapusAlso visit my web site ; vakantiehuisje
WOW just what I was looking for. Came here by searching for germay
BalasHapusHere is my web blog; germany
This design is incredible! You obviously know how to keep a reader entertained.
BalasHapusBetween your wit and your videos, I was almost moved to
start my own blog (well, almost...HaHa!) Excellent job.
I really loved what you had to say, and more than that, how you presented it.
Too cool!
my web blog :: vakantiehuis
Hello to all, how is everything, I think every one is getting
BalasHapusmore from this web page, and your views are pleasant designed for new users.
Stop by my web blog frances bean cobain tumblr
Wow, marvelous blog structure! How lengthy have you been running a
BalasHapusblog for? you made blogging glance easy. The full look
of your website is excellent, let alone the content material!
Check out my webpage :: grotevakantiehuizen.wordpress.com
This paragraph will assist the internet viewers for
BalasHapusbuilding up new blog or even a blog from start to end.
Feel free to visit my web-site vakantiehuizen frankrijk huren
Hello! Quick question that's totally off topic. Do you know how to make your site mobile friendly? My blog looks weird when viewing from my iphone4. I'm
BalasHapustrying to find a template or plugin that might be able to resolve this problem.
If you have any recommendations, please share.
Many thanks!
Check out my web blog ... luxe vakantiehuisjes frankrijk ()
kok programnya gak jalan ya pas dicoba :i;
BalasHapus