parent
99b6c6bcfa
commit
b3447f17d3
@ -1,2 +1,84 @@
|
|||||||
# qsy
|
# 冒泡排序
|
||||||
|
#include<stdio.h>
|
||||||
|
void bubble(int a[],int n)
|
||||||
|
{
|
||||||
|
int i,j,t;
|
||||||
|
for(i=1;i<n;i++)
|
||||||
|
{
|
||||||
|
for(j=0;j<n-i;j++)
|
||||||
|
{
|
||||||
|
if(a[j]>a[j+1])
|
||||||
|
{
|
||||||
|
t=a[j];
|
||||||
|
a[j]=a[j+1];
|
||||||
|
a[j+1]=t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int b[10];
|
||||||
|
for(int i=0;i<10;i++)
|
||||||
|
{
|
||||||
|
scanf("%d",&b[10]);
|
||||||
|
}
|
||||||
|
bubble(b,10);
|
||||||
|
for(int i=0;i<10;i++)
|
||||||
|
{
|
||||||
|
printf("%d",b[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# 快速排序
|
||||||
|
#include<stdio.h>
|
||||||
|
void qusort(int a[],int l,int r)
|
||||||
|
{
|
||||||
|
int i,j,t,k;
|
||||||
|
if(l>r)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
t=a[l];
|
||||||
|
i=l;
|
||||||
|
j=r;
|
||||||
|
while(i<j)
|
||||||
|
{
|
||||||
|
while(a[j]>=t&&i<j) j--;
|
||||||
|
while(a[i]<=t&&i<j) i++;
|
||||||
|
if(i<j)
|
||||||
|
{
|
||||||
|
k=a[i];
|
||||||
|
a[i]=a[j];
|
||||||
|
a[j]=k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a[l]=a[i];
|
||||||
|
a[i]=t;
|
||||||
|
qusort(l,i=1,a);
|
||||||
|
qusort(i+1,r,a);
|
||||||
|
}
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int a[100000],i=0,n;
|
||||||
|
scanf("%d",&n);
|
||||||
|
getchar();
|
||||||
|
char t;
|
||||||
|
while(i<n)
|
||||||
|
{
|
||||||
|
scanf("%d",&a[i]);
|
||||||
|
getchar();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
qusort(0,i-1,a);
|
||||||
|
int j;
|
||||||
|
for(j=0;j<i;j++)
|
||||||
|
{
|
||||||
|
printf("%d",a[j]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue