Пример #1
0
int main() {
    struct graph g;
    graph_fill(&g);

    graph_bfs(&g, 0);
    return 0;
}
Пример #2
0
bool graph_initiate(ge start, ge end, vertex **root, search_t STRATEGY)
{
    // first set all visited flags to 0
    // record where we need to start our search
    vertex *temp = (*root);
    vertex *begin = NULL;
    while (temp != NULL) {
        temp->visited = 0;
        if (temp->element == start) {
            begin = temp;
        }
        temp = temp->nextvertex;
    }
    if (begin == NULL) {
        printf("vertex %c does not exist in graph\n", start);
        return false;
    }
    printf("current search starts at %c\n", begin->element);
    if (STRATEGY == DFS) {
        return graph_check(start, end, begin);
    }
    if (STRATEGY == BFS) {
        queueroot = NULL;
        queuetail = NULL;
        return graph_bfs(begin);
    }
    if (STRATEGY == EULER) {
        printf("is graph euler? (0 - no, 1 - semi, 2 - complete): %d\n", is_graph_euler(begin));
        return true;
    }
    return false;
}
Пример #3
0
int main(void) {
   
    int d = 0;
    int i = 0;
    int x = 0;
    graph my_graph = NULL;


    if (1 == scanf("%d", &d)) {
        my_graph = graph_new(d);
    }
    while (2 == scanf("%d%d", &i, &x)) {
        graph_bi_add_edge(my_graph, i, x);
    }

    /*
    graph my_graph = graph_new(8);

    graph_bi_add_edge(my_graph, 0, 1);
    graph_bi_add_edge(my_graph, 0, 4);
    
    graph_bi_add_edge(my_graph, 1, 0);
    graph_bi_add_edge(my_graph, 1, 5);
    
    graph_bi_add_edge(my_graph, 2, 3);
    graph_bi_add_edge(my_graph, 2, 5);
    graph_bi_add_edge(my_graph, 2, 6);
    
    graph_bi_add_edge(my_graph, 3, 2);
    graph_bi_add_edge(my_graph, 3, 6);
    graph_bi_add_edge(my_graph, 3, 7);
    
    graph_bi_add_edge(my_graph, 4, 0);

    graph_bi_add_edge(my_graph, 5, 1);
    graph_bi_add_edge(my_graph, 5, 2);
    graph_bi_add_edge(my_graph, 5, 6);

    graph_bi_add_edge(my_graph, 6, 2);
    graph_bi_add_edge(my_graph, 6, 3);
    graph_bi_add_edge(my_graph, 6, 5);
    graph_bi_add_edge(my_graph, 6, 7);

    graph_bi_add_edge(my_graph, 7, 3);
    graph_bi_add_edge(my_graph, 7, 6);
    */
    
    graph_bfs(my_graph, 1);
    graph_print(my_graph);
    graph_free(my_graph);
    return EXIT_SUCCESS;
}
Пример #4
0
TEST(SEARCH, breath_first_search)
{
    int i;
    fsnode **list = newFSNodes();

    for (i = 0; i < FSNODE_N; i++)
    {
        printf("%d : ", i);
        graph_showList(list[i]);
    }
    graph_fsoper_init();
    graph_bfs(list, 0);
    printf("\n");
}
Пример #5
0
void test_six_vertex_complete_graph()
{
    Graph g = {
        6,
        { {0, 1, 1, 1, 1, 1, }, 
          {1, 0, 1, 1, 1, 1, },
          {1, 1, 0, 1, 1, 1, },
          {1, 1, 1, 0, 1, 1, },
          {1, 1, 1, 1, 0, 1, },
          {1, 1, 1, 1, 1, 0, }
        },
        {"a", "b", "c", "d", "e", "f"},
    };
  
    graph_bfs(g, printer);
}
Пример #6
0
void test_generic_graph()
{
    Graph g = {
      8,
      { {0, 1, 0, 0, 1, 1, 0, 0}, 
        {1, 0, 1, 0, 0, 0, 1, 0},
        {0, 1, 0, 0, 0, 0, 1, 0},
        {0, 0, 0, 0, 1, 0, 0, 1},
        {1, 0, 0, 1, 0, 0, 1, 1},
        {1, 0, 0, 0, 0, 0, 1, 0},
        {0, 1, 1, 0, 1, 1, 0, 0},
        {0, 0, 0, 1, 1, 0, 0, 0}
      },
      {"a", "b", "c", "d", "e", "f", "g", "h"},
    };

    graph_bfs(g, printer);   
}
Пример #7
0
void test_three_vertex_graph()
{
    Graph g = {3, {{0, 1, 0}, {1, 0, 1}, {0, 1, 0} }, {"a", "b", "c"} };
    
    graph_bfs(g, printer);
}