Skip to main content

Posts

Showing posts from February, 2012

Sample C Program To Implement Minimum Spanning Tree Using Functions, Pointers & Structures.

ALGORITHM: STEP 1: Start the program. STEP 2: Assign MAX a constant value of 20. STEP 3: Declare a structure edge with structure variable *front. STEP 4: Define the functions and variables required in the program globally. STEP 5: Call the function create_graph() inside the main function. STEP 6: Call the function make_tree(). STEP 7: Set a for loop using i. for(i = 1; i <= count; i++) STEP 8: Print the values of tree[i].u and tree[i].v STEP 9: Stop the program. FUNCTION OF CREATE_GRAPH ( ) STEP 1: Declare the local variables. STEP 2: Read the number of nodes n. STEP 3: Calculate the value of max_edge as max_edge = n * (n - 1) / 2. STEP 4: Set a for loop using i. for(i = 0; i <= max_edge; i++) STEP 5: Read the values of origin and destiny. STEP 6: Check whether origin and destiny are equal to 0. STEP 7: If so exit the loop using break statement STEP 8: Read the weight of the current edge wt. STEP 9: Check the following condition. if(or