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.
Yes this is possible ,but it increase the running time complexity of the code .

First you can make the outer loop for how many series it insert , in the above test case its 3.

Secondly you can make a inner loop which adds the number .

I am not sure the code is running but the logic helps you .

I am implementing the psuedo code using stack !

```
int n=5;
for(int count = 1 ; count <= 3 ;count++)
{
   for(int i=n ; i > n-5 ; i++)
    {
      push_on_stack(i);
    }
 n=n+5;
}

```