int main(int argc, const char * argv[]) {
    
    node_t* head = NULL;
    node_t* one = (node_t*)malloc(sizeof(node_t) * 1);
    one->data = 1;
    head = one;
    
    node_t* two = (node_t*)malloc(sizeof(node_t) * 1);
    two->data = 2;
    node_t* three = (node_t*)malloc(sizeof(node_t) * 1);
    three->data = 3;
    node_t* four = (node_t*)malloc(sizeof(node_t) * 1);
    four->data = 4;
    node_t* five = (node_t*)malloc(sizeof(node_t) * 1);
    five->data = 5;
    
    one->next = two;
    two->next = three;
    three->next = four;
    four->next = five;
    five->next = NULL;
    
    puts("before reverse");
    linked_list_print(head);
    
    puts("after reverse");
    head = linked_list_reverse(head);
    linked_list_print(head);
    
    
    return 0;
}
Example #2
0
File: 2.1.c Project: kkpattern/CTCI
int main() {
  MemoryPool *pool = memory_pool_init(sizeof(100) * 100);
  LinkedList *list = NULL;
  list = linked_list_append(list, memory_pool_alloc_int(pool, 1));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 2));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 3));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 2));
  list = linked_list_append(list, memory_pool_alloc_int(pool, 4));
  linked_list_print(list);
  remove_duplicates_in_place(list);
  linked_list_print(list);
  list = linked_list_free(list);
  memory_pool_free(pool);
  return 0;
}
Example #3
0
File: 2.4.c Project: kkpattern/CTCI
int main() {
  MemoryPool *pool = memory_pool_init(sizeof(100)*100);
  LinkedList *number_a = NULL;
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 3));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 1));
  number_a = linked_list_append(number_a, memory_pool_alloc_int(pool, 5));
  linked_list_print(number_a);
  LinkedList *number_b = NULL;
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 5));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 9));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 2));
  number_b = linked_list_append(number_b, memory_pool_alloc_int(pool, 1));
  linked_list_print(number_b);
  LinkedList *result = add(number_a, number_b, pool);
  linked_list_print(result);
  linked_list_free(result);
  linked_list_free(number_b);
  linked_list_free(number_a);
  memory_pool_free(pool);
  return 0;
}
Example #4
0
int prompt_user_name(
	char chosen_username[]
) {
	int ret = -1;
	struct linked_list *list_username;
	if (init_user_list(&list_username))
		goto ERROR;
	if (list_username != NULL)
		linked_list_sort(&list_username);
	while (1) {
		if (list_username != NULL) {
			printf("0. New User\n");
			linked_list_print(list_username);
		}
		if (use_user_list(list_username, chosen_username) == 0)
			if (*chosen_username != '\0')
				break;
	}
	ret = 0;
	ERROR:
		linked_list_free(list_username);
		return ret;
}
Example #5
0
int prompt_activity_name(
	char chosen_activity[]
) {
	int ret = -1;
	struct linked_list *list_activity;
	if (init_activity_list(&list_activity))
		goto ERROR;
	if (list_activity != NULL)
		linked_list_sort(&list_activity);
	while (1) {
		if (list_activity != NULL) {
			printf("0. New Activity\n");
			linked_list_print(list_activity);
		}
		if (use_activity_list(list_activity, chosen_activity) == 0)
			if (*chosen_activity != '\0')
				break;
	}
	ret = 0;
	ERROR:
		linked_list_free(list_activity);
		return ret;
}