Exemplo n.º 1
0
int main(int argc, char **argv) {

	//Array statistics
	double array[5] = {2.0, 3.89, -3.94, 10.1, 0.88};
	print_array_stats(array, 5);

	//Creating liked list with 3 3s and 4 4s
	linked_list *ll3 = new_linked_list(3, 3);
	linked_list *ll4 = new_linked_list(4, 4);

	//Should print: "3 3 3"
	print_linked_list(ll3, 1, 1);

	//Inserting a 5 at the 1st position
	insert_linked_list(ll3, 1, 5);

	//Should print "3 5 3 3"
	print_linked_list(ll3, 1, 1);

	//Printing backwards, should print: "3 3 5 3"
	print_linked_list(ll3, 1, 0);

	//Merging the linked lists
	merge_linked_list(ll3, ll4);

	//Printing the result, should print: "3 4 5 4 3 4 3 4"
	print_linked_list(ll3, 1, 1);

	//Summing the elements, should be 30
	printf("Sum: %d\n", sum_linked_list(ll3));

	//Freeing the memory of ll3
	destroy_linked_list(ll3);
}
Exemplo n.º 2
0
// Destroy all resource connected to a cache object
void destroy_cache(cache_t cache){
    //Destroy double linked list and hash table
    destroy_linked_list(cache->linked_list);
    destroy_hash_table(cache->hash_table);
    free(cache->hash_table);
    free(cache->linked_list);
}
Exemplo n.º 3
0
int main()
{
	Linked_List *linked_list = NULL;
	int error_code;
	int i;
	for(i = 0; i < SIZE_OF_LIST; ++i) {
		error_code = add_linked_list(&linked_list, i);
		if(error_code) {
			fprintf(stderr, "\nError. Adding item (%d) failed.\n", i);
			return EXIT_FAILURE;
		}
	}
	print_linked_list(linked_list);
	printf("\nReversing list...");
	error_code = reverse_linked_list(&linked_list);
	if(error_code) {
		fprintf(stderr, "\nError. Reversing list failed.\n");
	}
	print_linked_list(linked_list);
	printf("\nRemoving 3rd node from end of list...");
	error_code = remove_nth_from_end(&linked_list, 3);
	if(error_code) {
		fprintf(stderr, "\nError. Removing nth node list failed.\n");
	}
	print_linked_list(linked_list);
	destroy_linked_list(linked_list);
	return EXIT_SUCCESS;
}
Exemplo n.º 4
0
void destroy_dequeue(dec_t dec)
{
	destroy_linked_list(dec->priv->list);
	free(dec->priv);
	free(dec);
}
Exemplo n.º 5
0
void destroy_lifo(lifo_t lifo)
{
	destroy_linked_list(lifo->priv->list);
	free(lifo->priv);
	free(lifo);
}