コード例 #1
0
ファイル: sample-main2.c プロジェクト: Monorail/Schoolwork
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;
}
コード例 #2
0
ファイル: requests.c プロジェクト: cwz920716/tail.js
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;
}
コード例 #3
0
ファイル: sample-main3.c プロジェクト: hkajur/ArrayList
int main(void)
{
	char *str = NULL;

	ArrayList *myList = createArrayList(0);
	ArrayList *list = NULL;

	list = destroyArrayList(NULL);
	nullAssert(list, "destroyArrayList()");

	str = put(myList, NULL);
	nullAssert(str, "put()");

	str = get(NULL, -1);
	nullAssert(str, "get() (1/2)");

	str = get(myList, -1);
	nullAssert(str, "get() (2/2)");

	return 0;
}
コード例 #4
0
ファイル: sample-main1.c プロジェクト: hkajur/ArrayList
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;
}