
transposegraph function
By: a guest on
May 7th, 2012 | syntax:
C | size: 0.70 KB | hits: 44 | expires: Never
//Make new list, copy rows/columns to column/rows of new graph
intList *transposeGraph(intList *origGraph, int n) {
intList *adjVertices = calloc(n+1, sizeof (intList));
if (n <= 0) {
fprintf(stderr, "Enter a correct amount for vertices.\n");
exit(1);
}
int h;
for ( h = 0; h <= n; h++)
adjVertices[h] = NULL;
//Loop through original list, put old values into newly created list
int i;
for (i = 1; i <= n; i++) {
while (origGraph[i] != NULL) {
intList temp = origGraph[i];
adjVertices[first(origGraph[i])] = cons(i, adjVertices[first(origGraph[i])]);
origGraph[i] = rest(origGraph[i]);
free(temp);
}
}
return adjVertices;
}