[ create a new paste ] login | about

Link: http://codepad.org/VBAB0JBo    [ raw code | output | fork ]

C++, pasted on Jan 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <algorithm>
#include <iostream>
#include <functional>

void PrintNumbers(int * myArray)
{
    std::copy(myArray, myArray + 10, std::ostream_iterator<int>(std::cout, ","));
    std::cout << std::endl;
}

int main()
{
    int myArray[10] = {1,2,3,4,5,6,7,8,9,10};
    //Sort ascending
    std::sort(myArray, myArray + 10);
    PrintNumbers(myArray);
    //Sort descending
    std::sort(myArray, myArray + 10, std::greater<int>());
    PrintNumbers(myArray);
    return 0;
}


Output:
1
2
1,2,3,4,5,6,7,8,9,10,
10,9,8,7,6,5,4,3,2,1,


Create a new paste based on this one


Comments: