help with coding up kruskal pseudocode
i am working on kruskal algorithm using disjoint sets.
here's what i have for now:
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
void makeset(int);
int findset(int);
void unionset(int, int);
void linkset(int, int);
const int nmax = 1000001; // verticies.
const int mmax = 100000; // edges
int p[nmax];
int rank[nmax];
void makeset(int i)
{
p[i] = i;
rank[i] = 0;
return;
}
void unionset(int i, int j)
{
linkset(findset(i), findset(j));
return;
}
void linkset(int i, int j)
{
if(rank[i] > rank[j])
p[j] = i;
else
{
p[i] = j;
if(rank[i] == rank[j])
rank[j]++;
}
return;
}
int findset(int i)
{
int j, h, k;
j = i;
while(j != p[j])
j = p[j];
k = i;
while((h = p[k]) != j)
{
p[k] = j;
k = h;
}
return j;
}
/*
int kruskal()
{
}
*/
int main()
{
return 0;
}
here is the pseudocode that i need to rewrite using C++ but i am having trouble understanding how it can be done ...
MST-KRUSKAL(G, w)
1. A <- emptyset
2. for each vertex in V[G]
3. do Make-Set(v)
4. sort the edges of E into nondecreasing order by weight w
5. for each edge (u,v) in E, taken in nondecreasing order by weight
6. do if FIND-SET(u) not equal FIND_SET(v)
7. then A <- A U {(u,v)}
8. UNION (u,v)
9. return A
please any help will be appreciated
thanks

