13 Nisan 2010 Salı

C++ ile Bubble Sort Örneği

//www.ethemsulan.com
#include <cstdlib>
#include <iostream>
using namespace std;
 int buble(int a[ ],int buyuk){
         int hold;
         for(int i=0;i<buyuk-1;i++){
                 for(int k=0;k<buyuk-1;k++){
                         if(a[k]>a[k+1]){
                                         hold=a[k];
                                         a[k]=a[k+1];
                                         a[k+1]=hold;
                                      
                                         }
                         
                         }
                         
                 }                  
         }
        
int main(int argc, char *argv[])
{
    int a=14;
    int diz[14]={23,23,32,45,45,56,13,12,34,2,12,67,87,5};    
    buble(diz,a);
     for(int k=0;k<a;k++){
                          cout<<diz[k]<<' ';
     }
     cout<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Hiç yorum yok:

Yorum Gönder