Why elements 6,7,8,11,12,13,14? If you only want interior cells, you don't want 14.
As to "I'm at a point and I want the neighbors", that is neither traversing nor recursive, so asking for a traversal and recursive function isn't going to get you anywhere. Given that you are at position n, the neighbors in the last direction are going to be at +/- 1; the neighbors in the next-to-last direction are going to be at +/- (size of last dimension); the neighbors in the third-to-last direction are going to be at +/- (size of last dimension * size of next-to-last dimension), etc.
As to traversing, assuming you want to start at an interior cell, you want to start at the coordinate (1,1,1,...,1), which by the formula given above means you are at offset n, which can be calculated in general by
Code:
n = 0;
for (i = dim-1; i >=0; i--) {
n *= dimensions[dim];
n++;
}
From there, you can just move forward one space at a time. If the number of dimensions isn't known ahead of time, then I would just calculate the coordinates anew each time, and if you reach the end of a "row", then don't process. (You can "cheat" a little bit by knowing that you will have to skip two consecutive "elements": the last one in one row, and the first one in the next; and as you move up in dimensions you can skip more elements at a time. But that's going to be a little tricky to get correct, so I wouldn't do that unless you're running unacceptably slow.)