int main(void){ int i; char buffer[32]; ArrayList *L1 = createArrayList(10); ArrayList *L2 = createArrayList(30); FILE *ifp = fopen("names.txt", "rb"); printf("\nRead Names from file and add them to ArrayList l1\n"); // Read all names from the file and add them to L1. while (fscanf(ifp, "%s", buffer) != EOF) put(L1, buffer); printf("\nAdd Names to L2 in rev order\n"); // Add the names to L2 in reverse order. for (i = getSize(L1) - 1; i >= 0; i--) put(L2, get(L1, i)); // Print the contents of L1. printf("\n-- LIST 1: --\n"); printArrayList(L1); // Print the contents of L2. printf("\n-- LIST 2 (First Names): --\n"); printArrayList(L2); }
int main(void){ int i; ArrayList *testarr = createArrayList(10); for(i = 0;i<testarr->capacity;i++) put(testarr,"hi"); printArrayList(testarr); expandArrayList(testarr,30); trimArrayList(testarr); printArrayList(testarr); printf("MAIN: size is %d\nMAIN: cap is %d\n",testarr->size, testarr->capacity); return 0; }
int main(void) { ArrayList *L1 = createArrayList(-1); // Trim array list. This should reduce its capacity to 0. trimArrayList(L1); // Trim again. This should produce no output since capacity is already 0. trimArrayList(L1); // Print the empty list. printArrayList(L1); printf("Size of list: %d\n", getSize(L1)); // Destroy array list. Hopefully this won't segfault. L1 = destroyArrayList(L1); // Print the empty list. printArrayList(L1); printf("Size of list: %d\n", getSize(L1)); // Since L1 has been destroyed and is now NULL, the put() function should // return NULL if (put(L1, "Hello, world!\n") == NULL) printf("Awesome!\n"); else printf("Not so awesome!\n"); // Create new list and add strings to the end. Print out the strings we're // adding (to ensure put() is returning pointers to those strings). printf("%s\n", put(L1 = createArrayList(-1), "Hello,")); printf("%s\n", put(L1, "world!")); // Print L1 again. printf("Array list contents:\n"); printArrayList(L1); L1 = destroyArrayList(L1); return 0; }
void *popRQ(requests_t *r, FILE *fp, FILE *fp2) { item_t *item = pop_req_queue(r); void *ret; if (!item) return NULL; ret = item->req; if (fp) fprintf(fp, "%ld,%ld,%ld,%f,%f,%ld\n", (item->compute + item->io), item->compute, item->io, NZDivison(item->compute * 1.0, item->io * 1.0), NZDivison(item->wait * 1.0, item->compute * 1.0), item->wait ); if (fp2) { // printArrayList(&item->events, stdout); printArrayList(&item->events, fp2); } destroyArrayList(&item->events); uv__free(item); return ret; }
int main(void) { int i; char myString[100], *temp; ArrayList *myList = createArrayList(10); // add some strings to the array list for (i = 0; i < 30; i++) { // format my string sprintf(myString, "(string %02d)", i); // add string to end of array list temp = put(myList, myString); // print a little notification that the string was added printf("Added string: %s\n", temp); } // print out the contents of the array list. printArrayList(myList); return 0; }
int main(void) { int i; char buffer[32]; ArrayList *L1 = createArrayList(-1); ArrayList *L2 = createArrayList(-1); FILE *ifp = fopen("names.txt", "rb"); // Read all names from the file and add them to L1. while (fscanf(ifp, "%s", buffer) != EOF) put(L1, buffer); // Add the names to L2 in reverse order. for (i = getSize(L1) - 1; i >= 0; i--) put(L2, get(L1, i)); // Print the contents of L1. printf("\n-- LIST 1: --\n"); printArrayList(L1); // Print the contents of L2. printf("\n-- LIST 2 (First Names): --\n"); printArrayList(L2); // Swap last names with first names in L2. for (i = 0; i < getSize(L2); i++) { if (strcmp(get(L2, i), "Sean") == 0) set(L2, i, "Szumlanski"); else if (strcmp(get(L2, i), "Adam") == 0) set(L2, i, "Bouters"); else if (strcmp(get(L2, i), "Antoniya") == 0) set(L2, i, "Petkova"); else if (strcmp(get(L2, i), "Ashkan") == 0) set(L2, i, "Paya"); else if (strcmp(get(L2, i), "Grant") == 0) set(L2, i, "Van Horn"); } // Print the contents of L2. printf("\n-- LIST 2 (Last Names): --\n"); printArrayList(L2); // Print L1 (in reverse order) and L2, to match up first and last names. printf("\n-- COMBINED LISTS (First and Last Names): --\n"); for (i = 0; i < getSize(L2); i++) printf("%s %s\n", get(L1, getSize(L1) - 1 - i), get(L2, i)); // Add elements from L1 to the end of L1 (in reverse order). printf("\n"); for (i = getSize(L1) - 1; i >= 0; i--) printf("Adding %s to L1 ...\n", put(L1, get(L1, i))); // Print the contents of L1. printf("\n-- LIST 1: --\n"); printArrayList(L1); // Insert a string at the beginning of list L1. insertElement(L1, 0, "List of Names:"); // Print the contents of L1. printf("\n-- LIST 1: --\n"); printArrayList(L1); // Remove all elements from L1. while (getSize(L1)) removeElement(L1, 0); // Print L1, which is now an empty list. printf("\n-- LIST 1: --\n"); printArrayList(L1); // Destroy our lists. L1 = destroyArrayList(L1); L2 = destroyArrayList(L2); // Make sure L1 is good and destroyed (and that destroyArrayList doesn't // segfault when passed a NULL pointer). L1 = destroyArrayList(L1); // Print the empty lists one last time. printf("\n-- LIST 1: --\n"); printArrayList(L1); printf("\n-- LIST 2: --\n"); printArrayList(L2); return 0; }