각종 정렬 알고리즘 시간 효율, 데이터 이동 횟수 와 비교 횟수 비교 [데이터 구조]
4892 단어 데이터 구조
#include
using namespace std;
#define MAXN 100000000
int maxn;
int N[MAXN+5];
// Compare Move
long long InsertMove,InsertComp,BInsertMove,BInsertComp,QComp,QMove,BubbleComp,BubbleMove,ShellComp,ShellMove;
typedef struct{
int key;
//int m;
}ElemType;
typedef struct{
int len;
ElemType *r;//*r r[MAXNSIZE]
}sq;
void CreateNum(){
srand((unsigned)time(NULL));
for(int i=1;i<=maxn;i++){
N[i]=rand()%MAXN;
}
}
sq init(){
sq L;
L.len=maxn;
L.r=new ElemType[maxn+1];
for(int i=1;i<=maxn;i++){
L.r[i].key=N[i];
}
return L;
}
void InsertSort(sq &L){
int j;
for(int i=2;i<=L.len;i++){
InsertComp++;
if(L.r[i].keyL.r[0].key;j--,InsertComp++){
L.r[j+1].key=L.r[j].key;
InsertMove++;
}
L.r[j+1].key=L.r[0].key;
InsertMove++;
}
}
}
void BInsertSort(sq &L){
int j,l,r,temp;
for(int i=2;i<=L.len;i++){
temp=L.r[i].key;
l=1,r=i-1;
while(l<=r){
int m=(l+r)/2;
if(temp=l+1;j--) {
L.r[j].key=L.r[j-1].key;//L.r[j]=L.r[j-1];
BInsertMove++;
}
L.r[l].key=temp;
BInsertMove++;
}
}
void ShellInsert(sq &L,int dk){
int i,j;
for(i=dk+1;i<=L.len;i++){
ShellComp++;
if(L.r[i].key0&&L.r[0].key t=3 7 5 3 1 -> t=4
int dt[100];
for(int j=0;j=pivotkey) --high,QComp++;
L.r[low]=L.r[high],QMove++; //
while(low 3
e=clock();
cout<
결과 파일 로 출력
#include
using namespace std;
#define MAXN 100000000
int maxn;
int N[MAXN+5];
// Compare Move
long long InsertMove,InsertComp,BInsertMove,BInsertComp,QComp,QMove,BubbleComp,BubbleMove,ShellComp,ShellMove;
typedef struct{
int key;
//int m;
}ElemType;
typedef struct{
int len;
ElemType *r;//*r r[MAXNSIZE]
}sq;
void CreateNum(){
srand((unsigned)time(NULL));
for(int i=1;i<=maxn;i++){
N[i]=rand()%MAXN;
}
}
sq init(){
sq L;
L.len=maxn;
L.r=new ElemType[maxn+1];
for(int i=1;i<=maxn;i++){
L.r[i].key=N[i];
}
return L;
}
void InsertSort(sq &L){
int j;
for(int i=2;i<=L.len;i++){
InsertComp++;
if(L.r[i].keyL.r[0].key;j--,InsertComp++){
L.r[j+1].key=L.r[j].key;
InsertMove++;
}
L.r[j+1].key=L.r[0].key;
InsertMove++;
}
}
}
void BInsertSort(sq &L){
int j,l,r,temp;
for(int i=2;i<=L.len;i++){
temp=L.r[i].key;
l=1,r=i-1;
while(l<=r){
int m=(l+r)/2;
if(temp=l+1;j--) {
L.r[j].key=L.r[j-1].key;//L.r[j]=L.r[j-1];
BInsertMove++;
}
L.r[l].key=temp;
BInsertMove++;
}
}
void ShellInsert(sq &L,int dk){
int i,j;
for(i=dk+1;i<=L.len;i++){
ShellComp++;
if(L.r[i].key0&&L.r[0].key t=3 7 5 3 1 -> t=4
int dt[100];
for(int j=0;j=pivotkey) --high,QComp++;
L.r[low]=L.r[high],QMove++; //
while(low 3
e=clock();
fp<