void aff_opt_1(void) { int *tab; tab = create_tab(n); fill_tab(&tab); printf("\n%s - Tableau Initial :\n%s\t", COLOR, NONE); aff_tab(tab); printf("%s - Tri rapide :\n%s\t", COLOR, NONE); aff_tab(quicksort(tab, 0, n)); printf("\n"); free(tab); tab = create_tab(n); fill_tab(&tab); printf("%s - Tableau Initial :\n%s\t", COLOR, NONE); aff_tab(tab); printf("%s - Tri par fusion :\n%s\t", COLOR, NONE); aff_tab(fusionsort(tab, 0, n)); printf("\n"); free(tab); tab = create_tab(n); fill_tab(&tab); printf("%s - Tableau Initial :\n%s\t", COLOR, NONE); aff_tab(tab); printf("%s - Tri bulle :\n%s\t", COLOR, NONE); aff_tab(bubble_sort(tab)); printf("\n"); free(tab); tab = create_tab(n); fill_tab(&tab); printf("%s - Tableau Initial :\n%s\t", COLOR, NONE); aff_tab(tab); printf("%s - Tri selection :\n%s\t", COLOR, NONE); aff_tab(selectionsort(tab)); printf("\n"); free(tab); tab = create_tab(n); fill_tab(&tab); printf("%s - Tableau Initial :\n%s\t", COLOR, NONE); aff_tab(tab); printf("%s - Tri insertion :\n%s\t", COLOR, NONE); aff_tab(insertionsort(tab)); printf("\n"); free(tab); }
void move_reverse_case(char value, int *rev_c, char **cmd) { void (*options[9])(char, int *, char **); char opt[8]; int len; int i; i = -1; fill_tab(opt); len = my_strlen(*cmd); fill_fct_ptr(options); while (++i < 8 && opt[i] != value); if (i != 8) { if (value == 51) { (*rev_c)++; options[i](value, rev_c, cmd); } else options[i](value, rev_c, cmd); } else if ((value == 68 || value == 2) && (*rev_c) > 0) (*rev_c)--; else if ((value == 67 || value == 6) && (*rev_c) < len) (*rev_c)++; }
void ls_l(char *arg) { t_file file; t_file **tab; t_llu llu; llu.total = 0; if (!(fill_tab(&tab, arg, &llu))) return ; sort_tab(&tab, &llu); if (!g_d) print_total(&llu); printfilelist(tab, llu.size, arg); llu.i = 0; while (llu.i < llu.size) { file = *((t_file *)tab[llu.i]); if (g_re && S_ISDIR(file.stats.st_mode) && ft_strcmp(file.name, ".") && ft_strcmp(file.name, "..")) llu.total = 0, ft_putchar('\n'), ft_putstr(ft_burger(arg, '/', file.name)), ft_putendl(":"), ls_l(ft_burger(arg, '/', file.name)); llu.i++; } free_ls(tab, &llu); }
constraint_t *split_constraints (int *constraints, int nb_constraints, int k, tm_topology_t *topology, int depth) { constraint_t *const_tab = NULL; int nb_leaves, start, end; int i; const_tab = (constraint_t *)CALLOC(k,sizeof(constraint_t)); /* nb_leaves is the number of leaves of the current subtree this will help to detremine where to split constraints and how to shift values */ nb_leaves = compute_nb_leaves_from_level( depth + 1, topology ); /* split the constraints into k sub-constraints each sub-contraints 'i' contains constraints of value in [i*nb_leaves,(i+1)*nb_leaves[ */ start = 0; for( i = 0; i < k; i++ ){ /*returns the indice in contsraints that contains the smallest value not copied end is used to compute the number of copied elements (end-size) and is used as the next staring indices*/ end = fill_tab(&(const_tab[i].constraints), constraints, nb_constraints,start, (i+1) * nb_leaves, i * nb_leaves); const_tab[i].length = end-start; const_tab[i].id = i; start = end; } return const_tab; }
void start_random_nb_to_tab(void) { int nb; g_info.i = 0; srand(time(NULL)); nb = rand() % 3 + 2; if (nb == 3) start_random_nb_to_tab(); else fill_tab(nb, nb); }
int my_printf(char *fmt, ...) { va_list ap; char *ptr; t_tab *tab; char *flags_str; va_start(ap, fmt); ptr = fmt; flags_str = "disScpxXobmun%+ l"; tab = malloc(sizeof(t_tab) * 17); fill_tab(tab, flags_str); run(fmt, tab, ap); va_end(ap); }
static void sync_notebook_tab (GtkNotebook *notebook, GtkWidget *page, int page_num, EphyPermissionsDialog *dialog) { GtkWidget *widget; DialogTab *tab; widget = gtk_notebook_get_nth_page (notebook, page_num); g_return_if_fail (widget != NULL); tab = g_object_get_data (G_OBJECT (widget), TAB_DATA_KEY); g_return_if_fail (tab != NULL); fill_tab (tab); }
void epur_out_of_quote(t_data *data) { const int total_len = get_total_len(data); char *s; char *tmp; int i; int n; i = 0; n = 0; s = (char*)ft_memalloc(sizeof(char) * (total_len + 1)); while (data->line[i]) fill_tab(data, &i, &n, s); tmp = ft_strtrim(s); free(s); free(data->line); data->line = tmp; }
int main(int argc, char **argv) { int tab[5]; if (argc < 2) { printf("\033[01;06;33mUSAGE: n (positive) [start] [end] "); printf("[subdivision (strict positive)] [precision (positive)]\n"); printf("If an error occur, start will be a 0, end at 5000, "); printf("subdivision at 10000 and precision at 10\n\033[0m"); exit(EXIT_FAILURE); } else if ((tab[0] = atoi(argv[1])) < 0) { printf("You must enter a positive value for 'n' (arg 1)\n"); exit(EXIT_FAILURE); } fill_tab(tab, argv); rectangle(tab); trapeze(tab); simpson(tab); gauss(tab); return (0); }
t_letubbies tabulatoire(t_mort *rob_stark_mother, int i) { int **tab; int j; int k; t_mort *begin; j = 0; k = 0; begin = rob_stark_mother; while (rob_stark_mother) { rob_stark_mother = rob_stark_mother->next; k++; } tab = malloc(sizeof(int*) * k); while (j < k) tab[j++] = malloc(sizeof(int) * i); return (fill_tab(tab, begin, i, k)); }
int get_next_line(int const fd, char **line) { char static *s; if (line == NULL) return (-1); if (s == NULL) if ((s = (char *)malloc(sizeof(char))) == NULL) return (-1); if ((s = read_file(fd, s)) == NULL) return (-1); if ((*line = (char *)ft_memalloc(sizeof(char)\ * count_len_line(s) + 1)) == NULL) return (-1); if (s[0] != '\0') *line = fill_tab(*line, s); else { ft_strdel(&s); return (0); } return (1); }
void launch(t_info *info) { int n_path; int index; index = 0; n_path = amount_path(info->list, info); info->path = (t_room ***)ft_memalloc((n_path + 1) * sizeof(t_room **)); get_addend(info->list)->distance = 0; while (index < n_path) { put_val(info, 0); if ((info->path[index] = find_path(info)) == NULL) break ; reinit(info->list); index++; } info->tab = fill_tab(info, n_path); write(1, "\n", 1); if (info->b_path == 1) print_path(info, n_path, info->t_size); launch2(info, n_path); }
int read_file(int fd, char *av) { int xmax; int ymax; int y; int **tab; xmax = 0; ymax = 0; y = 0; first_read(fd, av, &xmax, &ymax); if (!(tab = (int **)malloc(sizeof(int *) * ymax))) return (-1); fd = open(av, O_RDONLY); while (get_next_line(fd, &av) > 0) { tab[y] = fill_tab(av, tab[y], &xmax); y++; free(av); } close(fd); get_tab(tab, xmax, ymax); return (0); }
void recursive_canonicalization(int depth, tm_topology_t *topology, int *constraints, int *canonical, int *perm, int n, int m) { constraint_t *const_tab = NULL; int nb_leaves,nb_subtrees; int k, prec, start, end; /* if there is no constraints stop and return*/ if( !constraints ){ assert( n == 0 ); return; } /* if we are at teh bottom of the tree set canonical to the 0 value: it will be shifted by update_canonical and return*/ if ( depth == topology->nb_levels ){ assert( n==1 ); canonical[0] = 0; return; } /* compute in how many subtrees we need to devide the curret one*/ nb_subtrees = topology->arity[depth]; /* construct a tab of constraints of this size*/ const_tab = (constraint_t *) MALLOC( nb_subtrees * sizeof(constraint_t) ); /*printf("tab (%d):",nb_subtrees,n);print_1D_tab(constraints,n);*/ /* nb_leaves is the number of leaves of the current subtree this will help to detremine where to split constraints and how to shift values */ nb_leaves = compute_nb_leaves_from_level( depth + 1, topology ); /* split the constraints into nb_subtrees sub-constraints each sub-contraints k contains constraints of value in [k*nb_leaves,(k+1)*nb_leaves[ */ start = 0; for(k = 0; k < nb_subtrees; k++){ /*returns the indice in contsraints that contains the smallest value not copied end is used to compute the number of copied elements (end-size) and is used as the next staring indices*/ end=fill_tab(&(const_tab[k].constraints), constraints, n,start, (k+1) * nb_leaves, k * nb_leaves); const_tab[k].length = end-start; const_tab[k].id = k; start = end; } /* sort constraint tab such that subtrees with the largest number of constraints are put on the left and managed first, this how we canonize subtrees*/ qsort(const_tab, nb_subtrees, sizeof(constraint_t), constraint_dsc); /*display_contsraint_tab(const_tab,nb_subtrees);*/ /* update perm such taht we can backtrack the changes between constraints and caononical To go from canonical[i] to the corresponding constraints[k] perm is such that perm[canonical[i]]=constraints[k]*/ update_perm(perm, m, const_tab, nb_subtrees, nb_leaves); /* recursively call each subtree*/ prec = 0; for(k = 0; k < nb_subtrees; k++){ /* the tricky part is here : we send only a subtab of canonical that will be updated recursively This will greatly simplify the merging*/ recursive_canonicalization(depth+1, topology, const_tab[k].constraints, canonical+prec, perm+k*nb_leaves, const_tab[k].length, nb_leaves); prec += const_tab[k].length; } /* merging consist only in shifting the right part of canonical*/ start = const_tab[0].length; for( k = 1; k < nb_subtrees ; k++){ update_canonical(canonical, start, start+const_tab[k].length, k * nb_leaves); start += const_tab[k].length; } /* FREE local subconstraints*/ for( k = 0; k < nb_subtrees; k++ ) if(const_tab[k].length) FREE(const_tab[k].constraints); FREE(const_tab); }