#include<iostream>
#include<iomanip>
using namespace std;
void bubble (int[], const int,int(*) (int , int));
void swap(int *, int *);
int ascending(int,int);
int descending(int,int);
int main()
{
const int arraySize =10;
int order;
int counter;
int a[arraySize]={2,6,4,8,10,12,89,68,45,37};
cout<<"Artan siralama icin 1 giriniz, \n"
<<"Azalan siralama icin 2 giriniz";
cin >> order;
cout<<"Datalarin hafizadaki orjinal sirasi\n";
for (counter=0; counter<arraySize; counter++)
cout<< setw(4)<<a[counter];
if (order==1)
{
bubble(a,arraySize,ascending);
cout<<"\n Artan Sekilde Siralama\n";
}
else //order==2
{
bubble(a,arraySize,descending);
cout<<"Azalan Şekilde Sıralama\n";
}
for (counter=0; counter<arraySize; counter++)
cout<<setw(4)<<a[counter];
cout<<endl;
return 0;
}
void bubble(int work[], const int size, int (*compare)(int,int))
{
for(int pass=1;pass<size;pass++)
{
for(int count=0; count<size-1; count++)
{
if((*compare) (work[count], work[count+1]))
{
swap(&work[count],&work[count+1]);
} //end if
}//end for
} //end for
}//end bubble
void swap(int *element1Ptr, int *element2Ptr) //Pointer kullanarak yer degistirme islemi
{
int hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
int ascending(int a, int b)
{
return b<a; //b a dan küçükse yer değiştir
}
int descending(int a, int b)
{
return b>a; //b a dan büyükse yer değiştir
}