i have this program i need to write it is supposed to extract 6 min numbers from matrix 4x4 and put them into 1d array. i'v written this code but it only finds 1 min element, i dont know how to find next 5 min elements, any help would be appreciated
Easiest way? Keep they "arrayOut" sorted, check each element of array[i][j] to the "worst" minima, copy if better, then swap into position.
1 2 3 4 5 6
if (array[i][j] < minima[5]) {
// Overwrite previous "6th minimum" as it is now nr 7 and doesn't have to be remembered.
minima[5] = array[i][j];
// Swap-walk it into position 't' so that minima[t-1] <= minima[t] <= minima[t+1].
while (t > 0 && minima[t] < minima[t-1]) std::swap(minima[t], minima[t-1]);
}