برنامه bubble Sort به صورت صعودی و نزولی
با عرض معذرت بابت زیاد بودن کد
#include <iostream.h>
#include <conio.h>
void geta (int [],int);
void getb (int [],int);
void copy1a (int [],int [],int);
void copy1b (int [],int [],int);
void copy2a (int [],int [],int);
void copy2b (int [],int [],int);
void bubblemaxa (int [],int);
void bubblemaxb (int [],int);
void bubblemina (int [],int);
void bubbleminb (int [],int);
void showmaxa (int [],int);
void showmaxb (int [],int);
void showmina (int [],int);
void showminb (int [],int);
int a[10],c[10];
int b[15],d[15];
//__________________________paiane elame vojode tavabe__________________________
int main ()
{
const int n=10;
const int m=15;
cout<<"lotfan araie 10 taee a ra vared konid"<<endl;
geta (a,n);
cout<<"lotfan araie 15 taee b ra vared konid"<<endl;
getb (b,m);
copy1a (a,c,n);
copy1b (b,d,m);
bubblemaxa (a,n);
bubblemaxb (b,m);
cout<<"==================================================================="<<endl;
cout<<"chape araie be sorate so'odi <<a>>"<<endl;
showmaxa (a,n);
cout<<"==================================================================="<<endl;
cout<<"chape araie be sorate so'odi <<b>>"<<endl;
showmaxb (b,m);
copy2a (a,c,n);
copy2b (b,d,m);
bubblemina (a,n);
bubbleminb (b,m);
cout<<"==================================================================="<<endl;
cout<<"chape araie be sorate nozoli <<a>>"<<endl;
showmina (a,n);
cout<<"==================================================================="<<endl;
cout<<"chape araie be sorate nozoli <<b>>"<<endl;
showminb (b,m);
cout<<"==============================================================="<<endl;
cout<<"==============================================================="<<endl;
getch();
return 0;
}//end of int main
//___________________________paiane farakhanie tavabe__________________________
void geta (int a[],int x)
{
int i;
for (i=0;i<x;i++)
cin>>a[i];
}//end of void get (int a[],int x)
//_________________paiane piade sazie tabe gereftane araieie a__________________
void getb (int b[],int x)
{
int i;
for (i=0;i<x;i++)
cin>>b[i];
}//end of void get (int b[],int x)
//__________________paiane piade sazie tabe gereftane araie b___________________
void bubblemaxa (int a[],int x)
{
int i,j,t;
for (j=x-1;j>0;j--)
{
for (i=x-2;i>=0;i--)
if (a[i+1]>=a[i]);
else
{
for (i=0;i<j;i++)
{
if (a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}//end of if
}//end of for i
}// end of else
}//end of for j
}//end of void bubblemax (int a[],int x)
//________________paiane piade sazie tabe sorte so'odie araie a_________________
void bubblemaxb (int b[],int x)
{
int i,j,t;
for (j=x-1;j>0;j--)
{
for (i=x-2;i>=0;i--)
if (b[i+1]>=b[i]);
else
{
for (i=0;i<j;i++)
{
if (b[i]>b[i+1])
{
t=b[i];
b[i]=b[i+1];
b[i+1]=t;
}//end of if
}//end of for i
}// end of else
}//end of for j
}//end of void bubblemax (int b[],int x)
//________________paiane piade sazie tabe sorte so'odie araie b_________________
void bubblemina (int a[],int x)
{
int i,j,t;
for (j=x-1;j>0;j--)
{
for (i=x-2;i>=0;i--)
if (a[i+1]<=a[i]);
else
{
for (i=0;i<j;i++)
{
if (a[i]<a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}//end of if
}//end of for i
}//end of else
}//end of for j
}// end of void bubblemin (int a[],int x)
//________________paiane piade sazie tabe sorte nozoli araie a__________________
void bubbleminb (int b[],int x)
{
int i,j,t;
for (j=x-1;j>0;j--)
{
for (i=x-2;i>=0;i--)
if (b[i+1]<=b[i]);
else
{
for (i=0;i<j;i++)
{
if (b[i]<b[i+1])
{
t=b[i];
b[i]=b[i+1];
b[i+1]=t;
}//end of if
}//end of for i
}//end of else
}//end of for j
}// end of void bubblemin (int a[],int x)
//________________paiane piade sazie tabe sorte nozoli araie b__________________
void showmaxa (int a[],int x)
{
int i;
for (i=0;i<x;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"==================================================================="<<endl;
cout<<endl;
}//end of void showmin (int a[],int x)
//________________paiane piade sazie namieshe so'odie araie a___________________
void showmaxb (int b[],int x)
{
int i;
for (i=0;i<x;i++)
cout<<b[i]<<" ";
cout<<endl;
cout<<"==================================================================="<<endl;
cout<<endl;
}//end of void showmin (int a[],int x)
//________________paiane piade sazie namieshe so'odie araie b___________________
void showmina (int a[],int x)
{
int i;
for (i=0;i<x;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"==================================================================="<<endl;
cout<<endl;
}//end of void showmin (int a[],int x)
//________________paiane piade sazie namieshe nozolie araie a___________________
void showminb (int b[],int x)
{
int i;
for (i=0;i<x;i++)
cout<<b[i]<<" ";
cout<<endl;
cout<<"==================================================================="<<endl;
cout<<endl;
}//end of void showmin (int a[],int x)
//________________paiane piade sazie namieshe nozolie araie b___________________
void copy1a (int a[],int c[],int x)
{
int i;
for (i=0;i<x;i++)
c[i]=a[i];
}//end of copy1a (int a[],int c[],int x)
//________________paiane piade sazie copye gerftan az araie a___________________
void copy1b (int [],int d[],int x)
{
int i;
for (i=0;i<x;i++)
d[i]=b[i];
}//end of copy1b (int [],int d[],int x)
//________________paiane piade sazie copye gerftan az araie b___________________
void copy2a (int a[],int c[],int x)
{
int i;
for (i=0;i<x;i++)
a[i]=c[i];
}//end of (int a[],int c[],int x)
//________________paiane piade sazie copye kardan dar araie a___________________
void copy2b (int a[],int c[],int x)
{
int i;
for (i=0;i<x;i++)
b[i]=d[i];
}//end of (int a[],int c[],int x)
//________________paiane piade sazie copye kardan dar araie a___________________