2021-11-08 16:56:46 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
|
2023-08-21 21:37:54 +02:00
|
|
|
void swap(char *string, size_t index_from, size_t index_target) {
|
|
|
|
char temporary = string[index_from];
|
|
|
|
string[index_from] = string[index_target];
|
|
|
|
string[index_target] = temporary;
|
2021-11-08 16:56:46 +01:00
|
|
|
}
|
|
|
|
|
2023-08-21 21:37:54 +02:00
|
|
|
void heap_algorithm(char *string, size_t number_of_elements_to_operate) {
|
2021-11-08 16:56:46 +01:00
|
|
|
if (number_of_elements_to_operate == 1) {
|
|
|
|
printf("%s\n", string);
|
|
|
|
} else {
|
2023-08-21 21:37:54 +02:00
|
|
|
heap_algorithm(string, number_of_elements_to_operate - 1);
|
2021-11-08 16:56:46 +01:00
|
|
|
for (size_t index = 0; index < number_of_elements_to_operate - 1; index++) {
|
|
|
|
bool is_even = number_of_elements_to_operate % 2 == 0;
|
2023-08-21 21:37:54 +02:00
|
|
|
swap(string, is_even ? index : 0, number_of_elements_to_operate - 1);
|
|
|
|
heap_algorithm(string, number_of_elements_to_operate - 1);
|
2021-11-08 16:56:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
char *string = input();
|
|
|
|
size_t string_length = strlen(string);
|
2023-08-21 21:37:54 +02:00
|
|
|
heap_algorithm(string, string_length);
|
|
|
|
free(string);
|
2021-11-08 16:56:46 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|