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

📄 bubblesort.h

📁 各种排序算法BubbleSort、DichotomySort、HeapSort、InsertSort、MergeSort、QuickSort、ShellSort、
💻 H
字号:
#ifndef BUBBLESORT_H
#define BUBBLESORT_H
#include<iostream.h>

template<class Elem>
class BubbleSort:public sort<Elem>
{
	public:
		BubbleSort(){compareNum = 0 ; moveNum = 0;};
		virtual void Sorts(Elem Array[], int n);////
		void print_b(Elem Array[], int n);
	private:
		int compareNum;/////比较次数
		int moveNum;/////移动次数
};
template<class Elem>
void BubbleSort<Elem>::Sorts(Elem Array[], int n)
{
	bool noSwap;
	for(int i = 0 ; i < n ; i++)
	{
		noSwap = true;
		for(int j = n-1 ; j >= i ; j--)
		{
			compareNum++;
			if(compare(Array[j] , Array[j-1]) == -1)
			{
				swap(Array , j , j-1);
				moveNum++;
				noSwap = false;
			}
		}
		if(noSwap)
			return;
	}
}
template<class Elem>
void BubbleSort<Elem>::print_b(Elem Array[], int n)
{
	cout<<"        冒泡排序法         "<<endl;
	cout<<"+++++++++++++++++++++++++++"<<endl;
	cout<<"比较次数:"<<compareNum<<endl;
	cout<<"移动次数:"<<moveNum<<endl;
	//print(Array , n);
}
#endif

⌨️ 快捷键说明

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