Bubble sort problem

I have been given a card game assignment. its initial steps are to perform bubble sort. I have looked over my code a 1000 times but can't figure out why the compiler says "stack around variable 'player1' has corrupted. Please help.

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
 #include <iostream>
using namespace std;

int main(){
	int current=0;
	int deck[52]={7,4,13,11,13,6,13,12,11,1,13,5,1,8,3,6,4,12,2,9,8,7,10,7,7,3,1,10,10,6,8,9,12,2,11,5,12,5,3,8,10,9,11,1,4,9,2,3,4,6,2,5};
	int player1[5];
	int player2[5];
	int player3[5];
	int player4[5];

	for(int p1_assign=0; p1_assign<5; p1_assign++){
		player1[p1_assign]=deck[p1_assign];
	}
	for(int p2_assign=5; p2_assign<10; p2_assign++){
		player2[p2_assign]=deck[p2_assign];
	}
	for(int p3_assign=10; p3_assign<15; p3_assign++){
		player3[p3_assign]=deck[p3_assign];
	}
	for(int p4_assign=15; p4_assign<20; p4_assign++){
		player4[p4_assign]=deck[p4_assign];
	}
	int temp=0;


	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player1[j]>player1[j+1]){
				temp=player1[j];
				player1[j]=player1[j+1];
				player1[j+1]=temp;
			}
		}
	}
	for(int i=0; i<5; i++)
		cout<<player1[i];
} 
If an array has N elements, then it is an error to access index N+M, like you do with players 2-4.
I don't understand @keskiverto :/
You do dereference, for example player2[8]. That is an error.
Thank you :D
Topic archived. No new replies allowed.