emkishan
BAN USERFor example,
Initially the linked list is
----------
| 1 |
It will be incremented until 9999
----------
| 9999 |
Now after the next increment, the linked list will add a new node as shown below:
---------- ----------
| 1| <---> | 0 |
This will happen until 19999. After this, again the 9999 is set to 0 and 1 will be added to other node's value. Thus, the linked list would be:
---------- --------
| 2 | <------->|0000|
This way, if we want to print the counter it is to print the values in the nodes together, which is 20000.
This way we can add nodes dynamically infinitely (until the system is out of memory ;) )
Let us say in the language, the range of integers is from 0-65535.
Use only the nearest 10-powered value - 1. In this case, 10^4 - 1 = 9999.
Keep a counter and increment it until 9999 (say Node-1).
When this value is reached, on next increment, set this counter to 0. Add a node and set the counter to 1 (say Node-2).
Again, count from 0-9999 in Node-1 and on next increment, set Node-1 to 0 and Node-2 to 2.
Continue this way and add extra node whenever required.
Store all these nodes in a doubly linked list for easy access.
Yes. exactly !!
- emkishan February 04, 2013