سرت حبابی Bubble sort
#include iostream.h>
#include stdio.h>
#include conio.h>
int getarray(int x[],int first)
{
int i;
for(i=0;i {
printf("Enter element %d : ",i+1);
scanf("%d",&x[i]);
}
return (x[first]);
}
int main()
{
int* x;
int first,left=0,temp,i;
printf("Enter Size of aray : ");
scanf("%d",&first);
x=new int[first];
getarray(x,first);
int flag = 0;
int pass=1;
while(pass<=first&&flag==0)
{
flag=1;
for(i=0;i<=first-pass-1;i++)
if(x[i]>x[i+1])
{
flag=0;
temp=x[i];
x[i]=x[i+1];
x[i+1]=temp;
}
pass=pass+1;
}
for(int k=0;k < first;k++)
printf("%d ,",x[k]);
cout < < endl < < endl;
getch();
return 0;
}
#include stdio.h>
#include conio.h>
int getarray(int x[],int first)
{
int i;
for(i=0;i
printf("%d ,",x[k]);
cout < < endl < < endl;
getch();
+ نوشته شده در ۱۳۹۱/۱۰/۰۵ ساعت 10:26 توسط مجید
|