コード例 #1
0
ファイル: test.c プロジェクト: qeesung/data-struct
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */
    int
main ( int argc, char *argv[] )
{
    int k=0;
    Graph my_graph;
    Graph my_graph1;
    my_graph = Init_Graph();
    my_graph1 = Init_Graph();
    Create_Graph(my_graph , "./udg_graph.info");
    Create_Graph(my_graph1 , "./udg_graph.info");
    Print_Graph(my_graph);
    printf("*******Get vertex**********\n");
    printf("the v3 name  is :%s\n",Get_Vertex(my_graph , 2));
    printf("*******Put vertex**********\n");
    Put_Vertex(my_graph , "V3" ,"XXOO");
    printf("the v3 name after changed is :%s\n",Get_Vertex(my_graph , 2));
    Put_Vertex(my_graph , "XXOO" ,"V3");
    printf("******First Adjacent*********\n");
    printf("The V1 first adjacent is :%s\n",Get_Vertex(my_graph,First_Adjacent(my_graph , "V1")));
    printf("******Next Adjacent*********\n");
    printf("and next adjacent is :");
    k = Next_Adjacent(my_graph , "V1",Get_Vertex(my_graph,First_Adjacent(my_graph , "V1")));
    while(k!=-1)
    {
        printf("%s\t",Get_Vertex(my_graph,k));
        k= Next_Adjacent(my_graph , "V1", Get_Vertex(my_graph , k));
    }
    printf("\n");
    printf("****** Insert_Vertex*********\n");
    Insert_Vertex(my_graph , "QQ");
    Print_Graph(my_graph);
    printf("****** delete_Vertex*********\n");
    Delete_Vertex(my_graph , "V2");
    Print_Graph(my_graph);
    printf("********Insert Arcs*********\n");
    Delete_Vertex(my_graph , "QQ");
    Insert_Vertex(my_graph , "V2");
    Insert_Arcs(my_graph , "V1","V2");
    Insert_Arcs(my_graph , "V3","V2");
    Insert_Arcs(my_graph , "V5","V2");
    Print_Graph(my_graph);
    printf("********Delete Arcs*********\n");
    Delete_Arcs(my_graph , "V1", "V2");
    Print_Graph(my_graph);
    printf("craete a new graph---------->\n");
    Print_Graph(my_graph1);
    system("sleep 5");
    printf("************DFS_TRAVERse**********\n");
    DFS_Traverse(my_graph1 , Visit);
    system("sleep 5");
    printf("***********BFS_TRAVERE*************\n");
    BFS_Traverse(my_graph1 , Visit);
    
    free(my_graph);
    my_graph=NULL;
    return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
コード例 #2
0
ファイル: BFS.C プロジェクト: deepak12cs46/Data-Structure-Lab
void Table(int vertex_num, int matrix [size][size],
struct   Vertex vert[size])
{
	int i, j;
	for (i = 0; i < vertex_num; i++)
	{
		vert [i].visit = F;
		vert [i].vertex_no = i+1;
		vert [i].info = 'A'+ i;
		vert [i].path_length = 0;
		vert [i].Edge_Ptr = NULL;
	}

	for (i =0; i < vertex_num ; i++)
		for (j =0; j < vertex_num ; j++)
			if (matrix [i][j] > 0 )
				vert [i].Edge_Ptr = Insert_Vertex (j, vert [i].Edge_Ptr);
}