void do_command(t_app *app, unsigned char command) { if (command == RA) rotate(&app->a); else if (command == RB) rotate(&app->b); else if (command == RR) { rotate(&app->a); rotate(&app->b); } else if (command == RRA) { reverse_rotate(&app->a); } else if (command == RRB) reverse_rotate(&app->b); else if (command == RRR) { reverse_rotate(&app->a); reverse_rotate(&app->b); } else do_command2(app, command); }
void lsort(t_env *e) { t_node *tmp; tmp = e->a->begin; if (tmp->data > tmp->next->data && tmp->next->data > tmp->next->next->data) ft_norme(e); else if (tmp->data > tmp->next->data && tmp->next->data < tmp->next->next->data && tmp->data < tmp->next->next->data) swap(e, 'a'); else if (tmp->data < tmp->next->data && tmp->next->data > tmp->next->next->data && tmp->data < tmp->next->next->data) { swap(e, 'a'); rotate(e, 'a'); } else if (tmp->data < tmp->next->data && tmp->next->data > tmp->next->next->data && tmp->data > tmp->next->next->data) reverse_rotate(e, 'a'); else if (tmp->data > tmp->next->data && tmp->next->data < tmp->next->next->data && tmp->data > tmp->next->next->data) rotate(e, 'a'); }
static void ontop(t_env *e, int value, int len) { int i; t_node *tmp; i = 0; tmp = e->a->begin; while (tmp) { if (tmp->data == value) { if (i <= len / 2) { while (e->a->begin->data != value) rotate(e, 'a'); return ; } else { while (e->a->begin->data != value) reverse_rotate(e, 'a'); return ; } } i++; tmp = tmp->next; } }
int main(int argc, char *argv[]) { FILE *fp; char row[32]; int *array; int i = 0; int index = 0; int len = 0; fp = stdin; fgets(row, sizeof(row), fp); len = atoi(row); fgets(row, sizeof(row), fp); index = atoi(row); array = (int *)malloc(sizeof(int) * len); memset(array, 0, len); if (array == NULL) { exit(1); } while (fgets(row, sizeof(row), fp) != NULL) { array[i] = atoi(row); i++; } clock_t t1 = clock(); reverse_rotate(&array, len, index); clock_t t2 = clock(); for (i = 0; i < len; i++) { printf("%d ", array[i]); } printf("\n"); printf("elapsed time: %f\n", (double)(t2 -t1)/ CLOCKS_PER_SEC); return 0; }
static void ft_norme(t_env *e) { swap(e, 'a'); reverse_rotate(e, 'a'); }