Prim's algorithm implemented in C. The assignment has code given, I just don't understand how my professor wants the input read in (through a file maybe?) and I'm not entirely sure how to implement it how he's asking. I'm hoping someone who better understands the algorithm and C can help. Thanks in advance! Go ahead and open the image in a new tab for better viewing zoom.
Skeleton:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define N 10
#define INF INT_MAX
typedef struct lnode {
int fromv;
int tov;
int weight;
struct lnode *next;
} lnode;
int main(int argc, char **argv) {
void getdata(int amtrx[][N], int *sz, int *stv);
int insertnode(lnode **lst, int from, int to, int wt);
void prims(int amtrx[][N], int n, lnode **lst);
void printpaths(lnode *lst);
void freelist(lnode **lst);
if (argc < 2) {
printf("Missing Filename.\n");
return(1);
} else if (argc > 2) {
printf("Too many arguments.\n");
return(1);
}
FILE *f = fopen(argv[1], "r");
if (f) {
} else {
printf("Failed to open the file\n");
}
return 0;
}
void getdata(int amtrx[][N], int *sz, int *stv) {
int i, j, nsz, nedg, fr, to, vtx, wt;
scanf("%d %d %d", &nsz, &nedg, &vtx);
for(i = 0; i < nsz; i++)
for(j = 0; j < nsz; j++)
amtrx[i][j] = INF;
for(i = 0; i < nedg; i++) {
scanf("%d %d %d", &fr, &to, &wt);
amtrx[fr][to] = wt;
amtrx[to][fr] = wt;
}
*sz = nsz;
*stv = vtx;
}
int insertnode(lnode **lst, int from, int to, int wt) {
}
void prims(int amtrx[][N], int n, lnode **lst) {
}
void printpaths(lnode *lst) {
}
void freelist(lnode **lst) {
}
e6.668
16 points
6.60
64.668 total cost
Due date: ;
total cost: 5t
Gicbais: binciude ciintta.hs