// test vector's functions int main(int argc, char **argv) { size_t i; vector_t v = VectorCreate(INITIAL_SIZE); if (v == NULL) return EXIT_FAILURE; for (i = 0; i < FINAL_SIZE; ++i) { int *x = (int*)malloc(sizeof(int)); if (x == NULL) return EXIT_FAILURE; *x = FINAL_SIZE - i; element_t old; // set the value to the position i in the vector // terminate the program if VectorSet failed if (!(VectorSet(v, i, x, &old))) return EXIT_FAILURE; } PrintIntVector(v); // free the values stored in the vector for (i = 0; i < VectorLength(v); ++i) free(VectorGet(v, i)); // free the vector VectorFree(v); return EXIT_SUCCESS; }
void ReadInput() //creates the digraph { int i, j, nodeNum; FILE *fp; fp = stdin; fscanf(fp, "%d", &numNodes); SkipToEndofLine(fp); nodes = (GraphNode *)malloc(numNodes*sizeof(GraphNode)); for (i=0; i<numNodes; i++) { fscanf(fp, "%d", &nodeNum); fscanf(fp, " ( %d ) ", &nodes[nodeNum].degree); nodes[nodeNum].adjNodes = (int *)malloc(nodes[nodeNum].degree*sizeof(int)); for (j=0; j<nodes[nodeNum].degree; j++) fscanf(fp, "%d", &nodes[nodeNum].adjNodes[j]); SkipToEndofLine(fp); } fclose(fp); printf("nodeNum (degree) adjNodes:\n"); for (i = 0; i < numNodes; i++) { printf("%d (%d)", i, nodes[i].degree); PrintIntVector(nodes[i].adjNodes, nodes[i].degree); } }
int main(int argc, char *argv[]) { uint32_t i; vector_t v = VectorCreate(4); if (v == NULL) return EXIT_FAILURE; for (i = 0; i < N; ++i) { // Place some elements in the vector. int *x = (int*)malloc(sizeof(int)); element_t old; VectorSet(v, i, x, &old); } PrintIntVector(v); return EXIT_SUCCESS; }