I want to make a bubble sort function of an array of pointers that each of the pointers point to another arrays - inside of function and i'm getting a error that i violated a writing location (Visual Studio)
P.S, I do (*parr)++ because the first value of each array shows the length of the array without the first value so i need to start bubble sorting from the second box (arr[1] and not arr[0] for example ).
can someone write to me how can i fix it?
Thanks for help
(I need to sort the values of the original arrays not the pointer of the arrays).
int main(void){
int i = 0;
int arr0[4] = { 3, 9, 6, 7 };
int arr1[3] = { 2, 5, 5 };
int arr2[1] = { 0 };
int arr3[2] = { 1, 6 };
int arr4[5] = { 4, 5, 6, 2, 1 };
int* parr[5] = { arr0, arr1, arr2, arr3, arr4 };
func1(parr);
system("PAUSE");
return (0);
}
void func1(int** parr)
{
int i;
int temp;
int j;
int k;
int length;
for (i = 0; i < 5; i++, (parr)++)
{
length = **parr;
(*parr)++;
for (j = 0; j < length-1; j++)
{
for (k = 0; k < length - j - 1; k++, (*parr)++)
{
if ((**parr)>(*(*parr + 1)))
{
temp = **(parr);
**(parr) = (*(*parr + 1));
(*(*parr + 1)) = temp;
}
}
}
}
}
intarray, and you're trying to bubble sort each array? Or you have fiveintarray and you're trying to bubble sort them all as-if one consecutive array? Update the question with the answer please. And I don't think(*parr)++is doing what you think, but I may be misunderstanding your question. And all of this is assuming you actually setup the pointer array correctly; something your question shows no evidence of whatsoever.