📄 selectsort.h
字号:
#ifndef SELECTSORT_H
#define SELECTSORT_H
#include<iostream.h>
template<class Elem>
class SelectSort:public sort<Elem>
{
public:
SelectSort(){compareNum = 0 ; moveNum = 0;};
virtual void Sorts(Elem Array[], int n);////
void print_s(Elem Array[], int n);
private:
int compareNum;/////比较次数
int moveNum;/////移动次数
};
template<class Elem>
void SelectSort<Elem>::Sorts(Elem Array[], int n)
{
for(int i = 0 ; i < n-1 ; i++)///for(int i = 0 ; i < n ; i++)选择剩余记录里最小的一个
{
int Smallest = i;
for(int j = i + 1 ; j < n ; j++)
{
if (compare(Array[j], Array[Smallest]) == -1)
{
Smallest = j;
}
compareNum++;
}
swap(Array,i,Smallest);
moveNum++;
}
}
template<class Elem>
void SelectSort<Elem>::print_s(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 + -