int main() { struct list_t *root; size_t s; int a=43,b=63,c=99,d=70,e=25,f=17,g=57,h=69,i=111,j=120,k=70,l=73,m=75; /* char z[100]="test"; */ /* z = "test"; */ root = list_init(); root = list_remove_rear(root); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &a); list_insert_rear(root, &b); root = list_insert_after(root,&c,3); list_insert_rear(root, &d); root = list_insert_front(root, &e); root = list_insert_front(root, &f); list_insert_rear(root, &g); root = list_remove_front(root); list_insert_rear(root, &h); root = list_insert_after(root,&i,5); root = list_insert_after(root,&j,120); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &l); root = list_remove_any(root,&l); list_insert_rear(root, &m); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); s = list_size(root); printf( "%d\n", (int)s); printf( "%d\n", search(root, &g) ); list_destroy(root); return 0; }
/* insert an item on specified position or to the end if position>lenght(list) */ struct list_t* list_insert_after(struct list_t* list, void *element, int pos) { struct list_t *walker, *next_element, *new_element; int i = 1; if ( pos == 1) { list = list_insert_front(list, element); } else if ( !is_empty_list(list) && pos > 1 ) { walker = list; while ( walker->next != 0 && ++i<pos) { walker = walker->next; } /* can insert record instead of the last element or after it */ if ( i == pos || i == (pos - 1) ) { next_element = walker->next; new_element = malloc( sizeof(struct list_t) ); new_element->next = next_element; new_element->data = element; walker->next = new_element; } } return list; }
void list_append(list *l, struct token *tk) { if (l->front == NULL) { list_insert_front(l, tk); return; } l->last = list_insert_after_node(l->last, tk); }
void list_emplace_front (linked_list_t list, void* val) { node_t n; n = node_create (); n->data = val; list_insert_front (list, n); }
int main() { int i; list_t l; l = list_init(); for (i = 10; i >= 0; i--) { list_insert_front(l, i); } list_print(l); printf("The max value is: %d\n", findmax(l->head)); list_finalize(&l); return 0; }
int main() { struct hash *my_hash, *my_hash2; int x; /* Testing Hash with Linked List items */ struct list_t *root, *root2, *root3; int a=43,b=63,c=99,d=70,e=25,f=17,g=57,h=69,i=111,j=120,k=70,l=73,m=75; root = list_init(); root2 = list_init(); root3 = list_init(); root = list_remove_rear(root); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &a); list_insert_rear(root, &b); root = list_insert_after(root,&c,3); list_insert_rear(root, &d); root = list_insert_front(root, &e); root = list_insert_front(root, &f); list_insert_rear(root, &g); root = list_remove_front(root); list_insert_rear(root, &h); root = list_insert_after(root,&i,5); root = list_insert_after(root,&j,120); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &l); root = list_remove_any(root,&l); list_insert_rear(root, &m); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); my_hash = hash_init("list"); hash_insert(my_hash, "key1", root); hash_insert(my_hash, "key2", root2); hash_insert(my_hash, "key3", root3); printf("%s\n",my_hash->hash_type); char* s_val = "key2"; char* r_val = hash_get(my_hash, s_val); printf("%s - %s\n", s_val, r_val); hash_iterate(my_hash); hash_destroy(my_hash); /* Testing Hash with Binary Tree items */ struct node *root_node = NULL, *root_node2 = NULL, *root_node3 = NULL; root_node = insert(root_node,5,NULL); root_node = delete_node(root_node,5); root_node = insert(root_node,7,NULL); root_node = insert(root_node,3,NULL); root_node = insert(root_node,6,NULL); root_node = insert(root_node,9,NULL); root_node = insert(root_node,12,NULL); root_node = insert(root_node,1,NULL); print_preorder(root_node); root_node = delete_node(root_node,7); my_hash2 = hash_init("tree"); hash_insert(my_hash2, "key1", root_node); hash_insert(my_hash2, "key2", root_node2); hash_insert(my_hash2, "key3", root_node3); hash_iterate(my_hash2); hash_destroy(my_hash2); return 0; }
void interface_2(List *list) { annotation_2(); while (1) { int key_1 = 0; int value_1 = 0; int n = 0; printf("Num of actinon(2):\n"); scanf("%d", &n); if (n == 0) break; if (n == 1) { printf("Key after each add\n"); int find_key = 0; scanf("%d", &find_key); if (!find_elem(list, find_key)) { printf("Try again, press 1\n"); continue; } printf("Key - Value\n"); scanf("%d%d", &key_1, &value_1); sData *ins_data = list_node_data_create(key_1, value_1); if (ins_data == NULL) { printf("ERRROR\n"); continue; } list_insert_after_elem(find_elem(list, find_key), ins_data); continue; } if (n == 2) { printf("Key before each add\n"); int find_key = 0; scanf("%d", &find_key); if (!find_elem(list, find_key)) { printf("Try again, press 1\n"); continue; } printf("Key - Value\n"); scanf("%d%d", &key_1, &value_1); sData *ins_data = list_node_data_create(key_1, value_1); if (ins_data == NULL) { printf("ERRROR\n"); continue; } list_insert_before_elem(find_elem(list, find_key), ins_data); continue; } if (n == 3) { printf("Key - Value\n"); scanf("%d%d", &key_1, &value_1); sData *ins_data = list_node_data_create(key_1, value_1); if (ins_data == NULL) { printf("ERRROR\n"); continue; } list_insert_front(list, ins_data); continue; } if (n == 4) { printf("Key - Value\n"); scanf("%d%d", &key_1, &value_1); sData *ins_data = list_node_data_create(key_1, value_1); if (ins_data == NULL) { printf("ERRROR\n"); continue; } list_insert_last(list, ins_data); continue; } if (n == 5) { list_print(list); continue; } if (n == 9) { annotation_2(); continue; } printf("Wrong input try again\n"); } }