I'm working with 2d arrays (which I kinda understand) and a bubbleSort, which I sorta but don't really understand and perhaps those * and & which I'm totally lost on, especially the * which can mean what it means or the opposite of what it means? I don't get that.
The problem I'm having is converting the bubblesort given in class to one that works with 2d arrays. It should list them alphabetically and I have to use char arrays, not String - which would probably simplify it considerably.
Here's the main method and my bubblesort method, I have alternate methods in use in this; but they seem to work and don't have a direct effect on my problems. These are mainly syntax problems mind you.
#include <iostream>
#include <stdlib.h>
#include <cctype>
#include <memory.h>
#include "logic.h"
using namespace std;
// & means location
// * value of location
char Names [ROW] [COLUMN];
bool Continue;
char * personsName; //this means location with *
int numNames;
void main ()
{
do {
for(int x = 0; x < 20; x++){
cout << "Enter a name, type END to stop: ";
personsName = readString ();
if(strcmp (personsName, "END") !=0){
strcpy_s(Names [x], personsName);
numNames++;
}
Continue = (strcmp (personsName, "END") != 0);
delete [] personsName;
}
printNames(Names);
bubbleSort(Names,numNames);
printNames(Names);
} while (Continue);
}
void bubbleSort(int C [] [COLUMN], int arraySize){
int NumChars = arraySize;
int i;
bool Sorted;
char Temp;
int NumberOfCompares;
NumberOfCompares = NumChars - 1;
do { // outer loop - keeps doing the inner loop until nothing changes
Sorted = true;
for (i = 0; i < NumberOfCompares; i++) // inner loop - compares each pair of values
if (toupper(*(C [i])) >toupper( *(C [i + 1])))
{
strcpy(Temp, *(C [i]));
strcpy(C [i],C [i + 1]);
strcpy(C [i + 1],Temp);
Sorted = false;
}
else;
NumberOfCompares--;
} while (!Sorted);
}