Don't like ads? PRO users don't see any ads ;-)
Guest

transposegraph function

By: a guest on May 7th, 2012  |  syntax: C  |  size: 0.70 KB  |  hits: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Make new list, copy rows/columns to column/rows of new graph
  2. intList *transposeGraph(intList *origGraph, int n) {
  3.     intList *adjVertices = calloc(n+1, sizeof (intList));
  4.    
  5.     if (n <= 0) {
  6.         fprintf(stderr, "Enter a correct amount for vertices.\n");
  7.         exit(1);
  8.     }
  9.    
  10.     int h;
  11.     for ( h = 0; h <= n; h++)
  12.         adjVertices[h] = NULL;
  13.  
  14.     //Loop through original list, put old values into newly created list
  15.     int i;
  16.     for (i = 1; i <= n; i++) {
  17.                 while (origGraph[i] != NULL) {
  18.                         intList temp = origGraph[i];
  19.                         adjVertices[first(origGraph[i])] = cons(i, adjVertices[first(origGraph[i])]);
  20.                         origGraph[i] = rest(origGraph[i]);
  21.                         free(temp);
  22.                 }
  23.     }
  24.  
  25.     return adjVertices;
  26. }