Help with Sorting an Array in a Blueprint?

Every time I try to connect the exec from the sequence of nodes I have to sort my array, my game crashes.

The array has 5 elements, index 0 being of highest value and index 4 being of lowest value.

I want to write in the integer variable value (“ST”) to the index’s value that is less than the value of ST, but only the index that is one index higher than the value that is larger than the ST value.

i.e.

ST = 76

Array is set at:

index 0 —> 100

index 1—> 75

index 2—> 50

index 3—> 30

index 4—> 10

Only substitute index 1 with ST value (76), not index 2 - 4

Could someone help me out?

I have tried While Loop, Add, MaxOfIntArray, RemoveIndex, other variations of exchanging an index value w/ a variable’s value.

If I have understood the algorithm correctly and assuming you have the values ordered descending in the array. You go from the bottom/last (index 4) and check if its higher.

if it is higher than the value 76 > (10) then store that index in a temporary variable e.g. HighestValidIndex = 4.

then you go to the next index (3) is it higher? 76>30, yep, HighestValidIndex=3

next index (2) is it higher? 76>50, yep, HighestValidIndex=2

next index (1) is it higher? 76>75, yep, HighestValidIndex=1

next index (0) is it higher? 76>100, nope!, Break the loop and store value of ST in the HighestValidIndex.(1)

so you get index 1 = 76.

The node that fixed my problem was Insert. A very useful node, if you have an array with 5 elements it will insert the value into the index you give it and push all other values (of higher index) up an element in the array. So even if you get a value stored to array element 5 it will not show up in the array because 0-4 will have been set, one of those indexes with your desired value. It basically made it so I can set a value and not have to worry about any numerically sorting techniques to replace the value that was replaced with the index above it if it was still of higher value (when trying to sort the array, 0 as highest 4 as lowest).

Hello, you may try to convert Buuble Sort algorithm into blueprints. Lets start from sample code:

void bubbleSort(int arr[], int n) 
{ 
   int i, j; 
   for (i = 0; i < n-1; i++)       
  
       // Last i elements are already in place    
       for (j = 0; j < n-i-1; j++)  
           if (arr[j] > arr[j+1]) 
              swap(&arr[j], &arr[j+1]); 
} 

This is C++ now let’s convert it into blueprint.

Hmm… screen size is to small… let me split it to parts, maybe it will help you.

Here we have two nested loops as it is in code refrence. Then we do this:

I Sort my table of saves by it’s creation date. Maybe this solution will help you.