Table of Contents
Write a program that reads in a list of 1000 numbers and prints them in the order they were entered. This is easy:
int c; double number; for (c = 0; c < 1000; ++c) { scanf("%lf", &number); printf("%f\n", number); }
integer :: i double precision :: number do i = 1, 1000 read *, number print *, number enddo
Now, write a program that reads a list of 1000 numbers from the standard input and prints them in reverse order.
In order to achieve this, the entire list must be stored in a way that it can be traversed backwards.
There are basically two places to store a list of values:
Whether it's better to store the list in a file or in RAM depends on how large the list is and how fast we need to be able to read the list backwards. Disks are much larger than RAM, so they will accommodate larger lists. RAM is many times faster than disk, however, and will therefore lead to a faster program.