For my data structures class we've been given a weird stack problem. Not sure what he's wanting. Here's the gist of it:
We're given an array with each element representing the index of the next element to visit. For example, index 0 has element 7, so we would then visit index 7. Index 7 has element 3, so we would then go to index 3. And so on. This ends at index 19, that has element -1. (Supposedly, this is how FAT works on windows).
If we output the indices as we get to them, we get the forward path through the array. As we do this, we push each visited index onto a stack. If we output each element popped of the stack, we will be given the backwards path through the array.
This is where I'm confused:
While you are popped off your stack, construct an array that will have links whose path will visit the elements in the opposite order of the original array. You should be able to start at the last element (#19) and follow the links to the first element (whick will contain a -1). Print out this array after it is constructed.
Is it asking to use this second array as the links to follow through the first array, or is it asking to just traverse the second array using the backwards links?
I wouldn't hard-code assigning -1 to index 0 like that, what if a change to the problem requires to you have a different starting point? (I doubt it, but still...magic numbers seem wrong)