# Answer to Question #73322 in C++ for Sani

Question #73322

Implement another function; pass the array (again using a pointer) to it. The function should then sort the array using the Bubble Sort algorithm. The function should use pointers for all computations (counter variables, traversal, swap).Give me code in c++

Expert's answer

#include <iostream>

using namespace std;

int sort(int* arr, int size)

{

int temp;

for (int i = 0; i < size - 1; i++)

{

for(int j = 0; j < size - i - 1; j++)

{

if(arr[j] > arr[j+1])

{

temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

}

}

int main()

{

int arr[10] = {6,8,25,9,65,3,57,12,4};

sort(arr, 10);

return 0;

}

}

using namespace std;

int sort(int* arr, int size)

{

int temp;

for (int i = 0; i < size - 1; i++)

{

for(int j = 0; j < size - i - 1; j++)

{

if(arr[j] > arr[j+1])

{

temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

}

}

int main()

{

int arr[10] = {6,8,25,9,65,3,57,12,4};

sort(arr, 10);

return 0;

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment