Bubble sort algorithm

I'm back again! This time, I'm supposed to write a function that calls the bubble sort algorithm. I seem to be having trouble printing the sorted array. I'm supposed to ask the user to input 10 double values, and sort them accordingly using hte bubble sort algorithm. Whenever it comes time to call the function, however, nothing happens. I'm using xCode, and I'm getting a green message, saying Thread 1: EXC_BAD_ACCESS(code=EXC_1386_GPFLT) As always, any help is greatly appreciated !!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 #include <iostream>
using namespace std;

void bubbleSort(double array[], int n=10)
{
    bool swapped = true;
    double j = 0, temp;
while (swapped)
{
    swapped = false; j++;
    for (int i = 0; i < n - j; i++)
        if (array[i] > array[i+1])
        {
            temp = array[i];
            array[i] = array[i+1];
            array[i + 1] = temp;
            swapped = true;
        }
        cout << temp << " ";
}
}


int main()
{
    int n=10;
    double array[n];
    cout << "Enter ten numbers to be sorted: ";
    
    for (int i = 0; i < 10; i++)
    {
        cin >> array[i];
    }
    
    bubbleSort(&array[10], n);

    
    return 0;
}
bubbleSort(array, n);
Topic archived. No new replies allowed.