language: C++ 4.7.2 (gcc-4.7.2)
date: 215 days 8 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
 
 
 
void Insert(int *S, int k)
{
        int key = S[k];
        int j = k-1;
        while(j>=0 && S[j] > key)
        {
                S[j+1] = S[j];
                j--;
        }
 
        S[j+1] = key;
}
 
 
void Insertionsort(int S[], int n)
{
        if(n>1)
                Insertionsort(S,n-1);
        Insert(S,n-1);
 
}
 
int main()
{
        srand ( time(NULL) );
        int S1_8[8];
        for(int i=0; i<8; i++)
                S1_8[i] = rand()%100;
 
        Insertionsort(S1_8,8);
 
        for(int i=0; i<8; i++)
        {
                cout << S1_8[i] << endl;
        }
 
        return 0;
}