# Sorting Algorithm

I'm working on my own sorting algorithm.
This is what i have so far. (I want to make it as basic as possible)

quantity is the length of the list.
pointer is the place where 'int i' is placed when found.
int j makes a traverse over list.
temporaries is a list where the replaced int's go to.

``````void Fluxinterflowsort()
{
int pointer = 0;
for (int i = 0; i < quantity; i++)
{
for (int j = 0; j < quantity; j++)
{
if (i == list[j])
{
temporaries[pointer] = list[pointer];
list[pointer] = i;
pointer += 1;
}

if (i == lijst[j])
{
temporaries[pointer] = list[pointer];
list[pointer] = i;
pointer += 1;
}
}
}
}
``````

This is the array before the sorting:
8
3
1
6
3
5
9
6
6
8

This is the array after the sorting:
1
1
3
3
5
5
6
6
6
6

The problem i came across was a duplication of numbers in the final result.
And i'm missing a couple of integers.

Can anybody see what i did wrong?

Sorry to disappoint you, but it is not a sorting algoritm.
Could you try higher numbers and see what happens ? For example 351, 5533, 104, 12048, and so on.

Could you provide a complete sketch, so others can test it ?

You do the if ( i == list [ j ] ) twice, so also the pointer is incremented twice.

Bubble sorting is easy to do, but not very efficient.

``````#define Size 10
unsigned int myArray[Size] = {
65535, 32727, 0, 5000,13245,23,7412,0,0,9512
};

template<typename T, size_t N>
void sort(T (&Arr)[N])
{
for (int i = N - 1; i > 0; --i)
{
for (int j = 0; j < i; ++j)
{
if (Arr[j] >= Arr[j + 1])
{
long Temp = Arr[j];
Arr[j] = Arr[j + 1];
Arr[j + 1] = Temp;
}
}
}
}

void setup()
{
Serial.begin(115200);

Serial.print("Unsorted \n");
for (byte i = 0; i < Size; i++)
{
Serial.println(myArray[i]);
}

sort(myArray);

Serial.println("Sorted");
for (byte i = 0; i < Size; i++)
{
Serial.println(myArray[i]);
}
}

void loop() {
}
``````