11166 - Simple integer sorting
raw download clone
C
views 20
,
size 772 b
#include <stdio.h>

int main(void)
{
    int t, n, temp;
    int v[10001];

    scanf("%d", &t);
    for(int i=1; i<=t; i++)
    {
        scanf("%d", &n);
        for(int j=1; j<=n; j++)
        {
            scanf("%d", &v[j]);
            for(int k=1; k<=j-1; k++)
            {
                if(v[k] > v[j])
                {
                    temp = v[j];
                    for(int l=j; l>=k+1; l--)
                        v[l] = v[l - 1];
                    v[k] = temp;
                    break;
                }
            }
        }
        for(int m=1; m<=n; m++)
        {
            printf("%d", v[m]);
            if(m != n)
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.