### Recursive function for sorting array

Hi all, i have this mini program that generates randomly 15 to 25 sized array.
This array then randomly generate lower and upper case letters.
So far i have gotten iterative swap to move all lower case to left side and all upper case to right side. Im' required to do it recursively too. but am having a hard time figuring out the base case and general case. here is the code i have for the parts i got working.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990`` ``````#include #include #include using namespace std; const int MAXSIZE = 25; void ConstructArray (char [], int); void printArray (const char [], int); void iterativeSwap (char [], int); int main () { char myArray [MAXSIZE]; srand (time(NULL)); int randomSize = rand() % 11 + 15; ConstructArray (myArray, randomSize); \\printArray (myArray, randomSize); \\iterativeSwap (myArray, randomSize); } void ConstructArray (char myArray [], int randSize) { char randUppcase, randLowcase; int randAlpha; for (int i = 0; i < randSize; i++) { randAlpha = rand() % 2 + 1; randUppcase = rand() % 26 + 65; randLowcase = rand() % 26 + 97; if (randAlpha == 1) randAlpha = randUppcase; else randAlpha = randLowcase; myArray [i] = randAlpha; } printArray (myArray, randSize); iterativeSwap (myArray, randSize); } void printArray (const char myArray [], int randSize) { cout << "Given the following array " << endl; for (int i = 0; i < randSize; i++) cout << myArray[i] << " "; cout << endl << endl; } void iterativeSwap (char myArray [], int randSize) { int i = 0; int j = randSize - 1; char temp; while (i != j) { if (myArray[i] >= 'A' && myArray[i] <= 'Z') { if (myArray[j] >= 'a' && myArray[j] <= 'z') { temp = myArray[i]; myArray[i] = myArray[j]; myArray[j] = temp; } else --j; } else ++i; } cout << "Iterative Swap" << endl; for(int i = 0; i < randSize; i++) cout << myArray[i] << " "; } ``````
Last edited on
Topic archived. No new replies allowed.