DS within the row - line ordering

Title Description

Given a set of data, sorting is done in ascending order using the line data.

- procedural requirements -

If you use C ++ only include a header file iostream; if using C language can only include a header file stdio

If the program include more than one header file, do not look at the code, for 0 process

 

We do not allow the use of third-party objects or functions to achieve the requirements of this title

 

Entry

Number of data n-, n-data

 

Export

Sort results every sort of trip-line

 

Sample input

7 34 23 677 2 1 453 3

Sample Output

23 34 677 2 1 453 3 23 34 677 2 1 453 3 2 23 34 677 1 453 3 1 2 23 34 677 453 3 1 2 23 34 453 677 3 1 2 3 23 34 453 677

prompt

#include<iostream>
using namespace std;
#define INF 0x7f
int n;
void printarray(int *array)
{
    for(int i=0;i<n;i++)
    {
        if(i!=n-1)
            cout<<array[i]<<" ";
        else
            cout<<array[i]<<endl;
    }
}
void Insertsort(int *array)
{
    int i,j,temp;
    for(i=1;i<n;i++)
    { /// The first element has been placed as the first element in the sorted sequence of 
        TEMP = Array [I]; /// sequentially extracts the first element of unsorted sequence 
        for (J = I; J> = . 1 Array && [J- . 1 ]> TEMP; J, )
        { /// sequentially with the sorted sequence comparison and right element 
            Array [J] = Array [J- . 1 ];
        }
        Array [j] = TEMP; /// case vacated at j, an element to be sorted into 
        printarray (array);
    }
}
 
int main ()
{
    cin>>n;
    int *array=new int[n];
    for(int i=0;i<n;i++)
        cin>>array[i];
    Insertsort(array);
    delete []array;
    return 0;
}

Guess you like

Origin www.cnblogs.com/SZU-DS-wys/p/12183070.html