Detecting a cycle in an undirected graph and printing the vertices if there is a cycle, printing no cycle otherwise
You've basically got it!

The usual way to record the cycle is to mark the predecessor or parent of each node: that is, the node from which it was first visited. Then you can follow the trail of parents to print out the cycle.