Question: Suppose I give input to a C++ program as follows:

`1 2 3 4 5 6 7 8 9 10 11 12 13 14 15`

C++ code:

```
int n;
for (int i = 0; i < 15; i++)
{
    std::cin >> n;
    // use the value of n to make changes
}

```

In the above code I can read the input sequentially,
 i.e. `1 2 3 4 5 6 7 8 9 10 11 12 13 14 15`.

Is there any way to read input directly (without using extra memory in C++ program) from the input stream in the following order:

`5 4 3 2 1 10 9 8 7 6 15 14 13 12 11`

First five digits in reverse order `5 4 3 2 1`, next five digits in reverse order `10 9 8 7 6`, ...

Answer: 
*No*.

You need to read the data as they flow into the input stream.

In your program then, you can re-order them in any way you like.
As noted in the comments, the best way to do this is to read them in the order they are given and sort them afterwards. 

```
// vector to hold the values
std::vector<int> values;
values.reserve(15); // reserve for better performance

int n;
for (int i = 0; i < 15; i++)
{
    std::cin >> n;
    values.push_back(n); // add value to back of vector
}

// sort the vector
std::sort(values.begin(), values.end());

// use the values in ascending order...
for (int i = 0; i < 15; i++) {
    std::cout << values[i];    
}

```