void int_radix_sort(int *lst, int *tmp, int n, int iii) { int group = 4; // int buckets = 1 << group; int buckets = 1 << group; int mask = buckets - 1; int cnt[buckets], map[buckets]; int loc; //INITIALIZE CNT ARRAY TO ALL ZEROS for (int i=0; i < buckets; i++) { cnt[i] = 0; } printf("\nlst\t"); print_lst(lst, n); // COUNT - works printf("\ncnt\t"); for (int i=0; i < n; i++) { cnt[(lst[i] >> iii) & mask]++; //printf("%d : %x : ", i, (lst[i] >> iii) & mask); } print_lst(cnt, buckets); // MAP - works printf("\nmap\t"); int j = 0; for (int i=0; i < buckets; i++) { map[i]=j; j=map[i]+cnt[i]; // printf("%d ", j); } print_lst(map, buckets); // MOVE printf("\nmov\t"); for (int i=0; i < n; i++) { tmp[map[(lst[i] >> iii) & mask]++] = lst[i]; //printf("%d ", map[(lst[i] >> iii) & mask]); } print_lst(tmp, n); printf("\n"); }
void print_lst(FILE *fp, lst_node root, int depth) { /* Print two spaces for every level of depth. */ int i; assert(root); /* Syntactic sugar */ fprintf(fp, "| "); for (i = 0; i < depth; i++) fprintf(fp, "- "); /* Print the node type. */ fprintf(fp, "%s ", NODE_NAME(root->node_type)); if (root->value_string != NULL) fprintf(fp, "%s", root->value_string); fprintf(fp, "\n"); /* Recurse on each child of the subtree root, with a depth one greater than the root's depth. */ lst_node child; for (child = root->left_child; child != NULL; child = child->right_sib) print_lst(fp, child, depth + 1); }
int ft_env(t_list *cmd_l, t_list *env_l) { t_list *env_c; char **arg; t_list *unset; int i; int illegal; i = 1; illegal = 0; if (!(start_env(env_l, &env_c, &arg, cmd_l))) return (1); if (!(no_arg_env(arg, &env_c, i))) return (help_env(&env_c)); unset = checkout(arg, &i, env_c, &illegal); if (!(unset_it(unset, &env_c))) return (help_env(&env_c)); get_set(arg, &i, &env_c); if (arg[i]) execute(arg + i, &env_c); else if (!illegal) print_lst(env_c); ft_lstdel(&unset, (void(*)(void*, size_t))del_content); free_tab2d(arg); ft_lstdel(&env_c, (void(*)(void*, size_t))del_content); return (1); }
int main(int argc, char **argv) { build_a_lst(*(argv+1)); print_lst(head); /* prints the table */ int_radix_sort(head); printf("%s\n", "=====SORT====="); // print_lst(head); /* prints the table but now sorted */ return 0; }
void check_size(t_struct *info) { if (info->nb_item >= info->row || info->size_w + 2 >= info->col) { clean_lst(info); ft_putstr_fd("Window is too small", 2); } else print_lst(info); }
int lst_finish(t_lst *lst, t_data *data) { int count; lst = format_lst(lst, data); print_lst(lst); count = lst_len(lst); free_lst(lst); return (count); }
static int no_arg_env(char **arg, t_list **env_c, int i) { if (!arg[i]) { free_tab2d(arg); print_lst(*env_c); ft_lstdel(env_c, (void(*)(void*, size_t))del_content); return (0); } return (1); }
main ( ) { int i ; List lst = NULL ; struct client_ds cds[] = { { "varadhan", 123, 321, 123 }, { "sanjay", 322, 323, 432 }, { "venni", 433, 435, 232 }, }; lst = MakeEmpty ( lst ) ; for ( i = 0; i < 3; i++ ) Insert ( &cds[ i ], lst, lst ) ; print_lst ( lst ) ; Delete ( "venni", lst ); Insert ( &cds[ 0 ], lst, lst ) ; print_lst ( lst ) ; return 0 ; }
int main(void) { CURL *curl; char *buffer = malloc(10000); time_t curtime; char *date = malloc(100); char url[1000]; jsmntok_t tokens[MAX_TOK]; t_calendar *lst = NULL; t_conf *conf = malloc(sizeof(t_conf)); t_serv udp_serv; /* INIT */ time(&curtime); bzero(&udp_serv, sizeof(t_serv)); curl = curl_easy_init(); get_time(&date, curtime); conf_update(conf, url, date); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); init_serveur_udp(&udp_serv); if(!curl) exit(0); while(1) { if (check_notif(&udp_serv)) { if (udp_serv.mesg[0] == 'U') printf("i'll update calendar\n"); else if (udp_serv.mesg[0] == 'P') printf("Someone is looking for me PING MODE on\n"); printf("{%s}\n",udp_serv.mesg); curl_easy_perform(curl); /* getting info from webservice with curl */ json_parse(buffer, tokens); /* parsing data from curl's buffer in the tokken's struct */ //clean_calendar(lst); lst = update_calendar(buffer, tokens); /* on clean l'ancien calendar et on update un nouveau */ break ; } usleep(500000); } printf("%s\n\n",buffer); print_lst(lst); printf(" %lu\n", curtime); curl_easy_cleanup(curl); return 0; }
int main() { // Create test list const int lst_length = 100; Node * head = create_range_n_lst (lst_length); // Print source list print_lst (head); // Process list of length n // Time complexity -- O(n) // Space complexity -- O(1) head = rearrange_lst (head); // Print rearranged list print_lst (head); // Delete list delete_lst (head); return 0; }
int main() { t_list *list = NULL; char *tmp; int size; tmp = (char *) ft_memalloc(sizeof(*tmp) * BUFF_SIZE); tmp = "content 42"; size = ft_strlen(tmp) * (int) sizeof(*tmp); list = ft_lstnew(tmp, size); printf("one\n"); printf("cont: %s\n", (char *) list->content); print_lst(list); printf("two\n"); return 0; }
void press_arrow(t_select *params, char key) { if (key == 66) { if (params->curs_y == params->size_list) params->curs_y = 1; else params->curs_y++; } else if (key == 65) { if (params->curs_y == 1) params->curs_y = params->size_list; else params->curs_y--; } print_lst(params); }
void press_delete(t_select *params) { t_lst *current; t_lst *prev; t_lst *next; current = get_current_elem(params); prev = current->prev; next = current->next; ft_memdel((void **)¤t->value); ft_memdel((void **)¤t); prev->next = next; next->prev = prev; ft_get_col_n(params); params->size_list -= 1; if (params->curs_y > params->size_list) params->curs_y--; print_lst(params); }
void deal_op(int opt, t_list **lst_a, t_list **lst_b) { t_list *op_lst; op_lst = NULL; if (!opt) { if (!(op_lst = get_op_lst())) return ; do_allop(lst_a, lst_b, &op_lst); ft_lstdel(&op_lst, (void(*)(void*, size_t))del_op); } else if (opt & OPT_A) { print_lst(*lst_a); ft_putchar('\n'); do_op(lst_a, lst_b); } }
void resolution(t_lst *lsta, t_lst *lstb) { if (verif_rotate_a(lsta) == 1) { rev_rotate(&lsta); apply_opt_v(lsta, lstb); } if (verif_rotate_a(lsta) == 2) { rotate(&lsta); apply_opt_v(lsta, lstb); } while (is_sort(lsta, lstb)) { while (a_is_sort(lsta) == 1) resolve_a(&lsta, &lstb); while (is_sort(lsta, lstb) == 2) resolve_b(&lsta, &lstb); remove_list(&lsta, &lstb); } ft_print_color(MAGENTA, "\n\nEnd:", 1); print_lst(lsta, lstb); }