#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <time.h>
#include<iomanip>
#include<array>
#include <algorithm>
usingnamespace std;
constint AS = 6;
void FillingRandomly(int [AS][AS]);
void printing(int[AS][AS]);
void forsorting(int[][AS], int);
int c;
int main()
{
int funny = 0;
int timpa = 0;
int counter = 0;
int Array[AS][AS];
srand(time(0));
FillingRandomly(Array);
cout << "The unsorted array is" << endl << endl;
printing(Array);
cout << "The sorted array is" << endl << endl;
forsorting(Array, funny);
printing(Array);
system("PAUSE");
return 0;
}
void FillingRandomly(int Array[AS][AS])
{for (int i = 0; i<AS; i++)
{
for (int j = 0; j<AS; j++)
Array[i][j] = rand()%87 +12;
}
}
void printing(int Array[AS][AS])
{
int counter = 0;
for (int i = 0; i<AS; i++)
{
for (int j = 0; j<AS; j++)
{
cout << setw(5) << Array[i][j];
counter++;
if (counter%AS == 0)
cout << endl << endl;
}
}
}
void forsorting(int Array[AS][AS], int funny)
{
int w=0;
int dice = 0;
int Brray[AS*AS];
int super = 0;
int space=0;
//Transofrming Array[][] into Brray[]
for (int i = 0; i < AS; i++)
{
for (int k = 0; k < AS; k++)
{
Brray[space] = Array[k][i];
space++;
}
}
//Bubble sorting in Brray[]
for (int passer = 0; passer < AS-1; passer++)
{
for (int timpa = 0; timpa < AS-1; timpa++)
{
if (Brray[timpa]>Brray[timpa + 1])
{
super = Brray[timpa];
Brray[timpa] = Brray[timpa + 1];
Brray[timpa + 1] = super;
}
}
}
//Transforming Brray[] into sorted Array[][]
for (int j=0;j<AS;j++)
for (int i=0;i<AS;i++)
{Brray[w]=Array[i][j];
}
w++;
}
Ok so here's my code. All I need done is the sorting part, Ive written the bubble sorting technique, and i double checked my course and it was the same logic. So what I would like to know is why is my array not sorted when I print it out on the screen.