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++
1
Expert's answer
2018-02-09T06:27:33-0500
#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;

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS