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

📄 sortdemo.cpp

📁 数据结构算法之各种排序算法比较
💻 CPP
字号:
// SortDemo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "SortDemo.h"
#include "math.h"
int main(int argc, char* argv[])
{long c=0,c1,c2,c3,s=0,s1,s2,s3;

   c1=c2=c3=c;s1=s2=s3=s;
	SqList L,L1,L2,L3;
	cout<<"==============================SortDemo=============================="<<endl;
	cout<<"Input the total number of the serial( >=5 ) : ";
	cin>>L.length;
	L1.length=L2.length=L3.length=L.length;
	L.r[0].key=L1.r[0].key=L2.r[0].key=L3.r[0].key=0;

  for(int i=1;i<=L.length;i++)
	 {cout<<"number"<<i<<" :";
	  cin>>L.r[i].key;
	  L1.r[i].key=L2.r[i].key=L3.r[i].key=L.r[i].key;
	   
  }
	cout<<"Initial Serial: ";
 for(i=1;i<=L.length;i++)
 {cout<<L.r[i].key<<" ";
  if(i%10==0&&i!=0)cout<<endl;
 }
 cout<<endl;
QSort(L1,1,L1.length,c1,s1);
cout<<"QSort:\t\t";
 for(i=1;i<=L1.length;i++)
   cout<<L1.r[i].key<<"\t";
  cout<<endl;
//
HeapSort(L2,c2,s2);
 cout<<"HeapSort: \t";
 for(i=1;i<=L2.length;i++)
   cout<<L2.r[i].key<<"\t";
 cout<<endl;
//
 int dlta[]={3,1};
 int t=2;
 ShellSort(L3,dlta,t,c3,s3);
  cout<<"ShellSort: \t";
  for(i=1;i<=L3.length;i++)
   cout<<L3.r[i].key<<"\t";
   cout<<endl;
 //cout<<c<<s;
cout<<"================Compare Each Arithmetic Below==============="<<endl;
cout<<"\t   ComparisionCount \t\t  ShiftCount"<<endl;
cout<<"QSort\t\t"<<c1<<"\t\t\t\t"<<s1<<endl;
cout<<"HeapSort\t"<<c2<<"\t\t\t\t"<<s2<<endl;
cout<<"ShellSort\t"<<c3<<"\t\t\t\t"<<s3<<endl;
cout<<"============================================================"<<endl;

	return 0;
}

⌨️ 快捷键说明

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