Skip to content

Commit 7565f10

Browse files
author
=
committed
New files are added
1 parent 2df9ee3 commit 7565f10

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

graphs/a.out

12.6 KB
Binary file not shown.

graphs/kruskals.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,r,c,k=0,temp,count=0;
5+
printf("Enter the number of vertex you want: ");
6+
scanf("%d",&n);
7+
int adj[n][n];
8+
int E[20],E1[20],E2[20];
9+
for(r=0;r<n;r++)
10+
{
11+
for(c=0;c<n;c++)
12+
{
13+
if(r>c)
14+
{
15+
printf("Enter the weight between %d and %d element: ",r+1,c+1);
16+
scanf("%d",&adj[r][c]);
17+
E[k]=adj[r][c];
18+
E1[k]=r+1;
19+
E2[k]=c+1;
20+
k++;
21+
}
22+
else
23+
{
24+
adj[r][c]=0;
25+
}
26+
}
27+
}
28+
//////////////////////////////////////////
29+
for(r=0;r<n;r++)
30+
printf("%d\t",r+1);
31+
printf("\n");
32+
for(r=0;r<n;r++)
33+
{
34+
for(c=0;c<n;c++)
35+
{
36+
printf("%d\t",adj[r][c]);
37+
}
38+
printf("\n");
39+
}
40+
///////////////////////////////////////////////////////////////////////////
41+
//form set S and E
42+
//sorting set E of edges
43+
printf("Printing the original edge array\n");
44+
for(r=0;r<k;r++)
45+
{
46+
printf("%d\t",E[r]);
47+
}
48+
printf("\n");
49+
for(r=0;r<k-1;r++)
50+
{
51+
for(c=r;c<k;c++)
52+
{
53+
if(E[c]<E[r])
54+
{
55+
temp=E[r];
56+
E[r]=E[c];
57+
E[c]=temp;
58+
temp=E1[r];
59+
E1[r]=E1[c];
60+
E1[c]=temp;
61+
temp=E2[r];
62+
E2[r]=E2[c];
63+
E2[c]=temp;
64+
}
65+
}
66+
}
67+
printf("Printing the sorted array of edge set E\n");
68+
printf("E Src Dst\n");
69+
for(r=0;r<k;r++)
70+
{
71+
printf("%d\t%d\t%d\n",E[r],E1[r],E2[r]);
72+
}
73+
printf("\n");
74+
////////////////////////////////////
75+
//main work
76+
r=0;
77+
while((count!=n)&&(r<k))
78+
{
79+
printf("Selecting %d edge that is between %d and %d vertex\n",E[r],E1[r],E2[r]);
80+
if()
81+
{
82+
//accept
83+
count++;
84+
}
85+
else if
86+
{
87+
//cycle
88+
//ignore
89+
}
90+
r++;
91+
}
92+
///////
93+
return 0;
94+
}

greedy/a.out

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)