Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- void Travel(int num_s, int num_d);
- const int dots = 7;
- int finish = 1;
- int graph[dots][dots] = {
- { 0, 1, 0, 0, 1, 0, 0 },
- { 1, 0, 1, 1, 1, 1, 0 },
- { 0, 1, 0, 1, 0, 1, 0 },
- { 0, 1, 1, 0, 0, 1, 1 },
- { 1, 1, 0, 0, 0, 0, 1 },
- { 0, 1, 1, 1, 0, 0, 1 },
- { 0, 0, 0, 1, 1, 1, 0 } };
- int path[dots];
- bool flag[dots];
- int main(){
- Travel(0, 0);
- return 0;
- }
- void Travel(int num_s, int num_d){
- if (num_s == dots && graph[path[dots-1]][finish] == 1){
- for (int i = 0; i < dots; i++){
- if (i!=dots-1)
- printf("%d ->", path[i]);
- else
- printf("%d", path[i]);
- }
- printf("\n");
- return;
- }
- if (flag[num_d] == true)
- return;
- path[num_s] = num_d;
- flag[num_d] = true;
- for (int i = 0; i < dots; i++){
- if (graph[num_d][i] == 0)
- continue;
- Travel(num_s + 1, i);
- }
- flag[num_d] = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment