t_list_i *push_swap(t_list_i *list) { t_list_i *pile_b; t_list_i *last_item; pile_b = NULL; last_item = NULL; while ((test_sort_croissant(list) == 0) || pile_b) { last_item = can_we_rotate(list); if (last_item && list->next && list->next->next) list = rotate_a(list); if (list->c < list->next->c) list = swap_a(list); if (list->c > list->next->c && (test_sort_croissant(list) == 0) && list->next && list->next->next != NULL) pile_b = push_b(&list, pile_b); if (pile_b && pile_b->next && pile_b->c > pile_b->next->c) pile_b = swap_b(pile_b); if (pile_b && pile_b->next && test_sort_decroissant(pile_b) && test_sort_croissant(list)) list = push_a(list, &pile_b); if (test_sort_croissant(list) && pile_b && pile_b->next == NULL) list = push_a(list, &pile_b); } return (list); }
static int read_raw(const PIXF_Info *info, void *imgbytes, size_t hsize) { unsigned char *iptr = (unsigned char *)imgbytes; size_t i, n; for (i = 0; i < info->height; i++) { n = fread(iptr, 1, hsize, info->f); if (n < hsize) { #ifdef PIXF_ENABLE_VERBOSE if (pixf_verbose) fprintf(stderr, "%s: unexpected EOF during reading of image data (expected %lu bytes, read %lu)\n", __func__, (unsigned long)hsize, (unsigned long)n); #endif return PIXF_ERR_READ; } /* if we are running on little-endian machine and sample size is more than 8 bits (aligned to 16 bits), swap bytes */ #if __BYTE_ORDER==__LITTLE_ENDIAN if (info->bps>8) swap_b(iptr,hsize); #endif if (info->bpp == 1) neg((void *)iptr,hsize); iptr += hsize; } return PIXF_ERR_OK; }
static void order_b(t_push **lista, t_push **listb, t_action **actions) { while (checklen(*listb) > 1 && !checkorder(*listb)) { if (get_last(*listb) < get_before_last(*listb)) { swap_b(lista, listb, actions); push_a(lista, listb, actions); } else break ; } }
void swap_ab(t_push **lista, t_push **listb, t_action **action) { swap_a(lista, listb, action); swap_b(lista, listb, action); }