冒泡排序(从前到后、从后到前)

#include
#include
using namespace std;

void BubbleSort(int a[],int n)//从小到大 
{
	for(int i=0;ia[j+1])
				swap(a[j],a[j+1]);
		}
	}
}

void bubbleSort(int a[],int n)//从小到大 
{
	for(int i=0;i=i;j--)//从后向前比较,将最小的移动到最前面,前面逐渐有序 
			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
			} 
 } 
int main()
{
	//freopen("in.txt","r",stdin);
	int n;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i

 

转载于:https://www.cnblogs.com/RenoStudio/p/10355115.html

你可能感兴趣的:(冒泡排序(从前到后、从后到前))