I am working on a project that sorts arrays inside the pointer arrays in a few different ways, though I am stuck on one way of sorting. The arrays are built in a way that the first number indicates the amount of numbers after it. For example, (3,0,23,1): this array has 3 numbers after the first index). I want to sort the array from lowest to highest number but I don't want to change the first index meaning the array will look like this (3,0,1,23). These are the arrays and the pointer array:
int arr1[] = { 3, 9, 6, 7 };
int arr2[] = { 2, 5, 5 };
int arr3[] = { 0 };
int arr4[] = { 1, 6 };
int arr5[] = { 4, 5, 6, 2, 1 };
int * pArr[SIZE] = { arr1, arr2, arr3, arr4, arr5 };
This code is for the sorting function
for (i = 0; i < SIZE; i++)
{
for (j = 1; j < pArr[i][0]+1; j++)
{
if (pArr[i][j] < pArr[i][j - 1])
{
temp = pArr[i][j];
pArr[i][j] = pArr[i][j - 1];
pArr[i][j - 1] = temp;
}
}
}
I would like to use bubble sort or selection sort only as I am new to programming and don't know too much about the other sorting methods.
Here you are.
The program output is