This page helped me: http://comments.gmane.org/gmane.comp.programming.algogeeks/30667
But let me see if I can explain this.
: 0s , . , 0s, ? , ?
Bentley "from" () "to" ( ( )) , , "top", - . , from[i] < top, .
:
:
top = 0
data = int array of integers of size 1,000,000
(all random values since we did not initialize it)
1 (i = 1 ). , ? . "from" .
from[i] = top
to[top] = i
data[i] = 0 (I don't think it matters whether you set it to 0 or your intended value of 3)
top++ (top is now 1)
, , , to[from[i]] == i . , from[i] < top, .
:
A) (.. top = 0)
from[i] < 0, . .
B) ( top > 0, , 1)
from[i] < top = > from[i] = 0. , to[from[i]] = i.
top = 2... n