Bubble sort

I was able to store the desired variables in player1[] and print them too but i can't seem to do this for the other 3 arrays as the output is somewhat strange. although the process is exactly the same for all arrays.. 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#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=0; p2_assign<5; p2_assign++){
		int i=5;
		player2[p2_assign]=deck[i];
		i++;
	}
	for(int p3_assign=0; p3_assign<5; p3_assign++){
		int i=10;
		player3[p3_assign]=deck[i];
		i++;
	}
	for(int p4_assign=0; p4_assign<5; p4_assign++){
		int i=15;
		player4[p4_assign]=deck[i];
		i++;
	}
	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<4; i++){
		for(int j=0; j<4; j++){
			if(player2[j]>player2[j+1]){
				temp=player2[j];
				player2[j]=player2[j+1];
				player2[j+1]=temp;
			}
		}
	}
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player3[j]>player3[j+1]){
				temp=player3[j];
				player3[j]=player3[j+1];
				player3[j+1]=temp;
			}
		}
	}
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(player4[j]>player4[j+1]){
				temp=player4[j];
				player4[j]=player4[j+1];
				player4[j+1]=temp;
			}
			
		} 
	}
	for(int i=0; i<5; i++){
			cout<<player1[i]<<endl;
	}
	for(int i=0; i<5; i++){		
			cout<<player2[i]<<endl;
	}
	for(int i=0; i<5; i++){
			cout<<player3[i]<<endl;
	}
	for(int i=0; i<5; i++){
			cout<<player4[i]<<endl;
	}
}
Look at what is happening here at this loop...

1
2
3
4
5
for(int p2_assign=0; p2_assign<5; p2_assign++){
		int i=5;
		player2[p2_assign]=deck[i];
		i++;
	}

first loop...
i = 5;
player2[0] = deck[5];
i = 6;
second loop...
i = 5;
player2[1] = deck[5];
i = 6;
third loop...
i = 5;
player2[2] = deck[5];
i = 6;

Do you see what is happening?
Oh, that was a really stupid mistake :p Thank you @manga :)
Topic archived. No new replies allowed.