Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 06-19-2013, 05:41 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › C / C++ v
« Previous 1 ... 7 8 9 10 11 ... 15 Next »

bubble sort algorithm

Home General Computer Multimedia Business Lounge

Pages (2): 1 2 Next »
Post Reply 
Tweet
Threaded Mode | Linear Mode
bubble sort algorithm
01-04-2012, 03:18 PM
Post: #1
syn_attack Away
execl("/bin/sh", "sh", NULL);
**
Moderators
Posts: 308
Joined: Sep 2011
Reputation: 55
bubble sort algorithm
Figure 1.0 : Pengertian "Bubble Sort Algorithm"

- "Bubble Sort Algorithm" adalah algoritma pengurutan sederhana "simple sorting algorithm". Algoritma tersebut bekerja dengan membandingkan setiap elemen dari array secara berurutan.

Figure 1.1 : Contoh pengurutan bertahap dari "Bubble Sort Algorithm"

- Misal ada array sebagai berikut :
Code:
int array[] = { 99, 22, 50, 89, 101 };

Metode pengurutannya sebagai berikut :

Langkah Pertama :
[*] (99, 22, 50, 89, 101) --> (22, 99, 50, 89, 101) : Pertama membandingkan 2 elemen pertama, dan menukarnya
[*] (22, 99, 50, 89, 101) --> (22, 50, 99, 89, 101) : Dengan syarat apabila (99 > 50)
[*] (22, 50, 99, 89, 101) --> (22, 50, 89, 99, 101) : Dengan syarat apabila (99 > 89)
[*] Apabila (99 > 101) maka akan ditukar, nah berhubung (99 < 101) maka 99 dan 101 tetap pada posisinya masing-masing

Figure 1.2 : Pseudocode (diambil dari wikipedia)
Code:
procedure bubbleSort( A : list of sortable items )
  repeat
    swapped = false
    for i = 1 to length(A) - 1 inclusive do:
      if A[i-1] > A[i] then
        swap( A[i-1], A[i] )
        swapped = true
      end if
    end for
  until not swapped
end procedure

Figure 1.3 : Implementasi dalam bahasa C
Code:
/*
* Bubble Sort implementation in C
* By : Paulus Gandung Prakosa_ (syn-attack)
*/

#include <stdio.h>
#include <stdlib.h>

static void bubble_sort(int array_state[], int array_length) {
    int temp;
   bool swap_value;
   int i;

   for (i = 1; i < array_length; i++) {
       if (array_state[i - 1] > array_state[i]) {
          temp = array_state[i];
         array_state[i] = array_state[i - 1];
         array_state[i - 1] = temp;
         swap_value = true;
      }
   }

   for (i = 0; i < array_length; i++) {
       printf("%d ", array_state[i]);
   }

   printf("\n");
}

int main(void) {
    int user_array[] = { 99, 22, 50, 89, 101 };
   int i;

   printf("[*] Unsorted array : ");
   for (i = 0; i < 5; i++) {
       printf("%d ", user_array[i]);
   }
   printf("\n");

   printf("[*] Sorted array : ");
   bubble_sort(user_array, 5);

   return (EXIT_SUCCESS);
}

sekian tutorial sederhana dari aku kakak-kakak devilzc0de sekalian, maaf kalau ada kata-kata aku yang tidak berkenan di hati kakak.....

Quote for today -->
"A Hacker is not about destroying something, but it's a person who like playing with his/her mindful cleverness" --Richard M Stallman
Visit this user's website Find all posts by this user
Quote this message in a reply
 Reputed by :  ketek(+1)
01-04-2012, 03:21 PM
Post: #2
Super Moderator Offline
Wahyu Adi Prasetyo
****
Global Moderators
Posts: 7,026
Joined: Jan 2010
Reputation: 237
RE: bubble sort algorithm
ijin belajar kk paulus gandung smangat
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2012, 03:22 PM
Post: #3
CitooZz Offline
./pemburu kimblak
**
Moderators
Posts: 1,311
Joined: Jun 2011
Reputation: 23
RE: bubble sort algorithm
ijin arsipin kakak bwt belajar tar mlm

thanks por cerrr ketawa
Find all posts by this user
Quote this message in a reply
01-04-2012, 03:23 PM
Post: #4
ketek Offline
bocah ingusan
*******
Administrators
Posts: 2,317
Joined: Jan 2010
Reputation: 409
RE: bubble sort algorithm
wew bubble sort ne ada di praktikum semester 1 waktu baru2 masuk lab malu malu

thankx om syn_attack mantap
Find all posts by this user
Quote this message in a reply
01-04-2012, 03:24 PM
Post: #5
syn_attack Away
execl("/bin/sh", "sh", NULL);
**
Moderators
Posts: 308
Joined: Sep 2011
Reputation: 55
RE: bubble sort algorithm
kakak linuxer46 ~# monggo dilihat-lihat dan selamat belajar kakak linuxer46......... smangat
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2012, 03:45 PM
Post: #6
whitecoinDC Offline
security dc :metal
**
Moderators
Posts: 732
Joined: Apr 2011
Reputation: 18
RE: bubble sort algorithm
ane klo nemu tutor om Paulus dijejelin alogaritma mulu, pusing... suram

exploit kernelnya gimana nih om? sama si programming jagoan assembly yang ane pesen mana? pasti lupa deh.. mau diwawancara nih sama penelitinya...

jangan lupa ya om Paulus, ane tunggu pm ente... ketawa
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2012, 05:46 PM
Post: #7
assala Away
Stay Cool and Be Positive ;)
**
Moderators
Posts: 2,202
Joined: Jan 2010
Reputation: 41
RE: bubble sort algorithm
wah ini ane pelajari waktu jaman kuliah awal² hmm

mantap om smiley_beer

btw, pesenan manual g++ ane udah nemu om peace
Find all posts by this user
Quote this message in a reply
01-04-2012, 06:07 PM
Post: #8
Killu4 Away
./Devilz Advisor
Posts: 744
Joined: Nov 2011
Reputation: 16
RE: bubble sort algorithm
Wew algoritma,ane cuman belajar pas semester 1 aja udh pusing
Find all posts by this user
Quote this message in a reply
01-04-2012, 07:25 PM (This post was last modified: 01-04-2012 07:27 PM by ketek.)
Post: #9
ketek Offline
bocah ingusan
*******
Administrators
Posts: 2,317
Joined: Jan 2010
Reputation: 409
RE: bubble sort algorithm
(01-04-2012 03:18 PM)syn_attack Wrote:  Figure 1.0 : Pengertian "Bubble Sort Algorithm"

- "Bubble Sort Algorithm" adalah algoritma pengurutan sederhana "simple sorting algorithm". Algoritma tersebut bekerja dengan membandingkan setiap elemen dari array secara berurutan.

Figure 1.1 : Contoh pengurutan bertahap dari "Bubble Sort Algorithm"

- Misal ada array sebagai berikut :
Code:
int array[] = { 99, 22, 50, 89, 101 };

Metode pengurutannya sebagai berikut :

Langkah Pertama :
[*] (99, 22, 50, 89, 101) --> (22, 99, 50, 89, 101) : Pertama membandingkan 2 elemen pertama, dan menukarnya
[*] (22, 99, 50, 89, 101) --> (22, 50, 99, 89, 101) : Dengan syarat apabila (99 > 50)
[*] (22, 50, 99, 89, 101) --> (22, 50, 89, 99, 101) : Dengan syarat apabila (99 > 89)
[*] Apabila (99 > 101) maka akan ditukar, nah berhubung (99 < 101) maka 99 dan 101 tetap pada posisinya masing-masing

Figure 1.2 : Pseudocode (diambil dari wikipedia)
Code:
procedure bubbleSort( A : list of sortable items )
  repeat
    swapped = false
    for i = 1 to length(A) - 1 inclusive do:
      if A[i-1] > A[i] then
        swap( A[i-1], A[i] )
        swapped = true
      end if
    end for
  until not swapped
end procedure

Figure 1.3 : Implementasi dalam bahasa C
Code:
/*
* Bubble Sort implementation in C
* By : Paulus Gandung Prakosa_ (syn-attack)
*/

#include <stdio.h>
#include <stdlib.h>

static void bubble_sort(int array_state[], int array_length) {
    int temp;
   bool swap_value;
   int i;

   for (i = 1; i < array_length; i++) {
       if (array_state[i - 1] > array_state[i]) {
          temp = array_state[i];
         array_state[i] = array_state[i - 1];
         array_state[i - 1] = temp;
         swap_value = true;
      }
   }

   for (i = 0; i < array_length; i++) {
       printf("%d ", array_state[i]);
   }

   printf("\n");
}

int main(void) {
    int user_array[] = { 99, 22, 50, 89, 101 };
   int i;

   printf("[*] Unsorted array : ");
   for (i = 0; i < 5; i++) {
       printf("%d ", user_array[i]);
   }
   printf("\n");

   printf("[*] Sorted array : ");
   bubble_sort(user_array, 5);

   return (EXIT_SUCCESS);
}

sekian tutorial sederhana dari aku kakak-kakak devilzc0de sekalian, maaf kalau ada kata-kata aku yang tidak berkenan di hati kakak.....

Quote for today -->
"A Hacker is not about destroying something, but it's a person who like playing with his/her mindful cleverness" --Richard M Stallman








om syn_attack aku ada masalah nih waktu compile ... ini kenapa ya om?

[Image: 20sx8n8.jpg]


truz itu variable swap_value, kok gak digunakan?
kalo gitu algo "repeat - until not swapped" dari pseudocode blum masuk di kode om paulus ketawa

mohon pencerahannya om.. belajar
Find all posts by this user
Quote this message in a reply
01-04-2012, 11:22 PM
Post: #10
syn_attack Away
execl("/bin/sh", "sh", NULL);
**
Moderators
Posts: 308
Joined: Sep 2011
Reputation: 55
RE: bubble sort algorithm
kakak ketek ~# coba di borland C++ 5.02 om ketek, pasti bisa.....

sebenarnya tipe data bool itu hanya terdapat di C++, tetapi walaupun itu kode C, tapi compiler standard punya borland itu C++ kakak, bukan kompiler asli ANSI C standard

kalau kompiler asli ANSI C, tipe data bool itu tidak ada kakak ketek...... wawa

mohon maaf kalau ada yang salah ya kakak....... ^_^
Visit this user's website Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Pages (2): 1 2 Next »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Thumbs Up [Tutor] Program Urutkan Data dengan metode insertion sort chentiz 4 167 12-10-2012 10:18 PM
Last Post: chentiz
  merge sort ack_attack 4 438 03-28-2012 09:36 PM
Last Post: RieqyNS13
  binary search algorithm syn_attack 5 572 01-04-2012 04:08 AM
Last Post: Bunga.Mataharry
  Message Digest-5 Algorithm in C syn_attack 15 1,287 10-29-2011 10:41 PM
Last Post: syn_attack

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 06-19-2013, 05:41 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE