#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int n;
vector <int> a,b,c;
bool Ins()
{
bool flag=false;
for(int i=1;i<n;i++)
{
int t=c[i];
for(int j=i;j>0;j--)
{
if(c[j]<c[j-1])
swap(c[j],c[j-1]);
else
break;
}
if(flag)
{
cout<<"Insertion Sort"<<endl;
return true;
}
if(c==b)
{
flag=true;
}
}
return false;
}
int main()
{
cin>>n;
int x;
for(int i=0;i<n;i++)
{
cin>>x;
a.push_back(x);
}
for(int i=0;i<n;i++)
{
cin>>x;
b.push_back(x);
}
c=a;
if(Ins()==false)
{
c=a;
int p=n;
make_heap(c.begin(),c.end());
while(c!=b&&p>=0)
{
pop_heap(c.begin(),c.begin()+p);
p--;
}
cout<<"Heap Sort"<<endl;
pop_heap(c.begin(),c.begin()+p);
}
for(int j=0;j<n;j++)
{
if(j)
cout<<' ';
cout<<c[j];
}
cout<<endl;
return 0;
}
1098. Insertion or Heap Sort (25)
最新推荐文章于 2020-07-27 10:19:37 发布