Using bubble sort to sort a vector

I am trying to use bubble sort to sort a vector of permutations. I was wondering if someone could help me find my error in program because it incorrectly sorts the program.

Last edited on
Btw, I know you didint do that function, you just copy pasted it - http://garrettwyrwas.com/bubblesort-a-vector-in-c/

Dunno why your function is of type vector and why you return the vector, you dont do anything with it. Just make it a void. Also, thats not how the bubble sort works. You need nested loop.

1
2
3
4
5
6
7
8
9
10
11
12
for (int k = 0; k < w.size(); k++)
		{
			for (int i = 0; i < w.size() - 1; i++){
				if (w[i] > w[i + 1])
				{
					temp = w[i];
					w[i] = w[i + 1];
					w[i + 1] = temp;
					finished = false;
				}
			}
		}
Topic archived. No new replies allowed.