mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 03:10:07 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
void librarySort(int *index, int n)
|
||||
{
|
||||
void librarySort(int *index, int n) {
|
||||
int lib_size, index_pos,
|
||||
*gaps, // gaps
|
||||
*library[2]; // libraries
|
||||
@@ -19,8 +18,7 @@ void librarySort(int *index, int n)
|
||||
target_lib = 0;
|
||||
library[target_lib][0] = index[0];
|
||||
|
||||
while (index_pos < n)
|
||||
{
|
||||
while (index_pos < n) {
|
||||
// binary search
|
||||
int insert = std::distance(
|
||||
library[target_lib],
|
||||
@@ -29,23 +27,19 @@ void librarySort(int *index, int n)
|
||||
|
||||
// if there is no gap to insert a new index ...
|
||||
|
||||
if (numbered[insert] == true)
|
||||
{
|
||||
if (numbered[insert] == true) {
|
||||
int prov_size = 0, next_target_lib = !target_lib;
|
||||
|
||||
// update library and clear gaps
|
||||
|
||||
for (int i = 0; i <= n; i++)
|
||||
{
|
||||
if (numbered[i] == true)
|
||||
{
|
||||
for (int i = 0; i <= n; i++) {
|
||||
if (numbered[i] == true) {
|
||||
library[next_target_lib][prov_size] = gaps[i];
|
||||
prov_size++;
|
||||
numbered[i] = false;
|
||||
}
|
||||
|
||||
if (i <= lib_size)
|
||||
{
|
||||
if (i <= lib_size) {
|
||||
library[next_target_lib][prov_size] =
|
||||
library[target_lib][i];
|
||||
prov_size++;
|
||||
@@ -54,9 +48,7 @@ void librarySort(int *index, int n)
|
||||
|
||||
target_lib = next_target_lib;
|
||||
lib_size = prov_size - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
numbered[insert] = true;
|
||||
gaps[insert] = index[index_pos];
|
||||
index_pos++;
|
||||
@@ -64,17 +56,14 @@ void librarySort(int *index, int n)
|
||||
}
|
||||
|
||||
int index_pos_for_output = 0;
|
||||
for (int i = 0; index_pos_for_output < n; i++)
|
||||
{
|
||||
if (numbered[i] == true)
|
||||
{
|
||||
for (int i = 0; index_pos_for_output < n; i++) {
|
||||
if (numbered[i] == true) {
|
||||
// std::cout << gaps[i] << std::endl;
|
||||
index[index_pos_for_output] = gaps[i];
|
||||
index_pos_for_output++;
|
||||
}
|
||||
|
||||
if (i < lib_size)
|
||||
{
|
||||
if (i < lib_size) {
|
||||
// std::cout << library[target_lib][i] << std::endl;
|
||||
index[index_pos_for_output] = library[target_lib][i];
|
||||
index_pos_for_output++;
|
||||
@@ -82,8 +71,7 @@ void librarySort(int *index, int n)
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
// ---example--
|
||||
int index_ex[] = {-6, 5, 9, 1, 9, 1, 0, 1, -8, 4, -12};
|
||||
int n_ex = sizeof(index_ex) / sizeof(index_ex[0]);
|
||||
|
||||
Reference in New Issue
Block a user