Exemplo n.º 1
0
/* you need to do this before passing it to dfs or bfs */
struct searchInfo *
searchInfoCreate(Graph g)
{
    struct searchInfo *s;
    int n;

    s = malloc(sizeof(*s)); /* space for struct searchInfo, s is pointer to this space */
    assert(s);

    s->graph = g;
    s->reached = 0;

    n = graphVertexCount(g);

    s->preorder = createEmptyArray(n);
    s->time = createEmptyArray(n);
    s->parent = createEmptyArray(n);
    s->depth = createEmptyArray(n);

    return s;
} 
Exemplo n.º 2
0
Arquivo: main.c Projeto: PierreGts/SDA
static StringArray* createArrayFromFile(const char* fileName)
{
  // Open file
  FILE* file = fopen(fileName, "r");
  if (!file)
  {
    fprintf(stderr, "Error while loading file '%s': %s\n",
            fileName, strerror(errno));
    return NULL;
  }

  // Create the Array
  StringArray* result = createEmptyArray();
  if (!result)
  {
    fprintf(stderr, "Memory allocation error while reading file %s\n", fileName);
    return NULL;
  }


  // Read file line by line
  char* line = readLine(file);
  while (line != NULL)
  {
    if (!insertInArray(result, line))
    {
      fprintf(stderr, "Memory allocation error while reading file %s\n", fileName);
      freeArray(result, true);
      return NULL;
    }

    line = readLine(file);
  }

  fclose(file);
  return result;
}