我正在尝试解决这个问题http://www.mycodeschool.com/work-outs/sorting/7 问题是在插入排序中找不到任何变化。
我已经编写了代码,但无法弄清楚我在逻辑上哪里出错了
#include<iostream>
#include<cstdio>
#include<cmath>
// Include headers as needed
using namespace std;
int main()
{
// Write your code here
int T,count,n,*a;
// int imin;
cin >> T;
int value,hole;
while(T--)
{
cin >> n;
count=0;
a=new int[n];
//reading the input array
for(int i=0;i<n;i++)
{
cin >> a[i];
}
// considering the 0th element to be already sorted and
// remaining list unsorted
for(int i=1;i<n;i++)
{
value=a[i];
hole=i;
// shifting
while(hole>0&&a[hole-1]>value)
{
// …Run Code Online (Sandbox Code Playgroud)