The biggest error was that your requirement is to visit each edge a maximum of once, but you were tracking nodes.
Also, I recommend always using {}
braces after your if
s, while
s, etc. You have some misleading whitespace in your post.
GCC 4.7.3: gcc -Wall -Wextra backtrace.c
#include <stdio.h>
int edges[12][12] = {
{0,1,0,0,0,0,0,0,0,0,0,0},
{1,0,1,1,1,1,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,1,1,0,0,1,1,0,0,0,0},
{0,1,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,1,0},
{0,0,0,0,1,1,0,0,1,1,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,1,1,1,1,0,1},
{0,0,0,0,0,0,0,0,0,0,1,0}
};
int visited[12][12] = {
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0}
};
int counter = 0;
struct Node {
int node;
struct Node *prev;
};
void print(struct Node* p) {
do
printf ("%d%s", p->node + 1, (p->prev != NULL)? "<-" : "\n");
while ((p = p->prev) != NULL);
printf("%d\n", ++counter);
}
void flag(int i, int j) {
visited[i][j] = visited[i][j] ? 0 : 1;
visited[j][i] = visited[j][i] ? 0 : 1;
}
void visit (int first, int last, struct Node *prev_node) {
struct Node n = { first, prev_node };
if (first == last){ print(&n); return; }
int i;
for (i=0; i<12; ++i){
if ((visited[first][i] == 0) && (edges[first][i] == 1)) {
flag(first, i);
visit(i, last, &n);
flag(first, i);
}
}
}
int main (int argc, char *argv[]) {
visit (0, 11, NULL);
return 0;
}