This answer on Stackoverflow is pointing to a Java code sample implementing DFS with stack.
Besides, if you feel comfortable with C and I hope you like chess as me too, I strongly advise you to study Andy DuPlain's fbk2rbm's source code released in the public domain.
It's a handy utility to convert Fritz power-books to Rebel 7 format (Opening libraries in the chess parlance).
It makes use of stack, chess move beeing seen as node.
Excerpt :
...
/* Used to hold move */
struct Move {
char FromFile, FromRank;
char ToFile, ToRank;
unsigned char Eval;
char StartVar;
};
/* List of moves seen */
struct Move Moves[256];
...
Extending the program to address position cylcing detection (given that different move sequences may lead to the same position / collision) would be an excellent exercise related to your question.