Help with Bubblesort and Arrays

Hi, this is my first time using this website, i have been taking a programming class at my high school this semester and i have been enjoying it alot. I fell a bit behind a few weeks ago and for some reason went forward onto the next project before doing this one. The project is a statistics program for arrays/vectors. I was making progress on the program until i encountered an error when i tried buidling.
I am using code::blocks 13.12 .

The point where the error occurs is line 26. Here is the error:

error: no match for 'operator<<' in 'std::operator<< <std::char_traits<char> >((* & std::cout), ((const char*) "Sort: " )) << name '
error: candidates are:

And then there is a bunch of stuff that would take forever to copy w/o copy&paste (the code:blocks is installed on my school's virtual computers, so i can only copy and paste into them)


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
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>


using namespace std;
void mysort(vector<int> &v);
int main(){

    int size, i, data, n;



    cout << "Please Enter the desired size of your array: ";
    cin >> size;

    vector<int>name(size);
    for (i=0; i < size; i++) {
        cout << "array[" << i << "]: ";
        cin >> data;
        name[i] = data;

    }

    mysort(name);

    cout << "Sort: " << name << '\n';
    cout << "n: " << size << '\n';



return 0;
}

void mysort (vector<int> &v) {
    int temp;
    bool isfinished = false;
    while (!isfinished) {
        isfinished = true;
        for (int i = 0; i < v.size() - 1; i++) {
            temp = v[i];
            v[i] = v[i + 1];
            v[i + 1] = temp;
            isfinished = false;
        }
    }
    

}
Last edited on
When printing out the vector contents at line 26, you need to take a similar approach as you did in getting the data into the array, using a for loop and individual elements.

Check the logic in your sort function - isfinished gets set to false at the end of the for loop - how is the while loop going to exit?
Topic archived. No new replies allowed.