⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 排序 -- 冒泡排序法[anank].cpp

📁 包含选择排序法
💻 CPP
字号:
/******************************************************************************************************
** Program Name : Bubble Sort
** Author       : Lu Jian Hua
** Time         : 2007-9-5 
*******************************************************************************************************/

#include <iostream>
using namespace std ;

const int MAX_SIZE = 10;

void Bubble_Sort(int *a, const int SIZE) ;

int main()
{
	int a[MAX_SIZE] = { 0 } ;
	cout << "-------------- Bubble Sort ----------------------" << endl << endl 
		 << "Please Enter The Numbers : " << endl << endl ;

	for (int i=0; i<MAX_SIZE; i++)
	{
		cout << "a[" << i << "] : " ;
		cin  >> a[i] ;
	}

	cout << "Before Sorting : " ;

	for (i=0; i<MAX_SIZE; i++)
		cout << a[i] << " " ;

	Bubble_Sort(a, MAX_SIZE) ;

	cout << endl << endl ;

	cout << "After  Sorting : " ;

	for (i=0; i<MAX_SIZE; i++)
		cout << a[i] << " " ;

	cout << endl << endl ;

	cout << "-------------- Selection Sort ----------------------" << endl << endl ;

	return 0 ;
}

void Bubble_Sort(int *a, const int SIZE) 
{
	int temp = 0 ;

	for (int i=SIZE-1; i>=1; i--)				// I : SIZE-1 ~ 1
	{
		for (int j=0; j<=i-1; j++)				// J :    0   ~ I-1
		{
			if (a[j] > a[j+1])
			{
				temp = a[j] ;
				a[j] = a[j+1] ;
				a[j+1] = temp ;
			}
		}
	}
}


/********************************************************************************
*
* Notice : This Program Can Be Launched In VC6.0 Environment
*
********************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -