bubblesort.cpp

来自「四种排序算法的比较」· C++ 代码 · 共 50 行

CPP
50
字号
// BubbleSort.cpp: implementation of the BubbleSort class.
//
//////////////////////////////////////////////////////////////////////

#include "BubbleSort.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

BubbleSort::BubbleSort()
{

}

BubbleSort::~BubbleSort()
{

}

void BubbleSort::bubbleSort()
{  
	int iTemp;  
	for(int i=1;i<BubbleSort::Count;i++)  
	{	  
		for(int j=BubbleSort::Count-1;j>=i;j--)  
		{  
			if(BubbleSort::data[j]<BubbleSort::data[j-1])
			{  
				iTemp = BubbleSort::data[j-1];  
				BubbleSort::data[j-1] = BubbleSort::data[j];  
				BubbleSort::data[j] = iTemp;  
			}  
		}  
	}  
}  
void BubbleSort::Init(int n)
{
	data=new int[n];
	Count=n;
	cout<<"Please input the data:"<<endl;
	for(int i=0;i<n;i++)
		cin>>data[i];
} 
void BubbleSort::Show()
{
	cout<<"The result is:"<<endl;
	for(int i=0;i<BubbleSort::Count;i++)
		cout<<data[i]<<"  ";
} 

⌨️ 快捷键说明

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