### an old assignment that I cannot seem to solve

Part II (5 points)

In the source file, declare another array of circles with 6 elements. Using a looping statement to put the circles in the array a into the newly declared array by following rules:

1. The first circle in the array a goes to the first element of the new array.

2. If a circle in array a is greater than all the circles in the new array, then put this circle after the last circle in the new array, otherwise, insert this circle right in front of the first circle in the new array that is greater than or equal to this circle.

I think I am missing one small part. the array prints sorted in ascending order but it repeats a value, that repeated value is taking the place of a value that is being left out for some reason. Please help. all operators that need to be overloaded have been overloaded.

 ``12345678910111213141516171819202122`` `````` Circle a[6] = { Circle(9),Circle(7),Circle(3),Circle(5),Circle(11),Circle(90) }; Circle temp; Circle newArray[SIZE]; newArray[0] = a[0]; for (int i = 0; i < SIZE; i++) { for (int j = i + 1; j < SIZE; j++) { if (newArray[i] > a[j]) { temp = newArray[i]; newArray[i] = a[j]; newArray[j] = temp; } else { newArray[j] = a[j]; } } }``````
Bubble sort requires that the elments are already present in the array. Either you copy the array before you sort or you use another sorting algorithm like insertion sort. See:

https://www.hackerearth.com/practice/algorithms/sorting/insertion-sort/tutorial/
Thank you very much :)
Topic archived. No new replies allowed.