First, some comments about your functions.
The directions say to write a swap function, but you're doing it directly in your function performing the partition, which is oddly named iterativeSwap instead of iterativePartition.
So, you'll need a swap function.
About the base case for recursion:
In your iterative version, the while loop goes until i==j.
This would also be your base case condition in recursivePartition
if(i==j) return;
The general case is just the same thing you're doing in the while loop.
Then, just call recursivePartition( myArray, i, j ) again.
EDIT: In my version I'm bumping both i and j each time, so I can get i > j (they may cross each other). My base case condition has to watch for this, so I have
if(i>=j) return;
This would correspond to having while(i<j) in the iterative version.
This also allows me to bump i and j following each swap
mySwap( myArray[i++], myArray[j--] );
since may as well get off the elements just swapped. The post increment (not pre increment) is essential there.
EDIT2: Not to get on you about your code in ConstructArray (it works), but it does afford an opportunity to suggest reducing the steps involved.
Your code:
1 2 3 4 5 6 7 8 9 10
|
randAlpha = rand() % 2 + 1;
randUppcase = rand() % 26 + 65;
randLowcase = rand() % 26 + 97;
if (randAlpha == 1)
randAlpha = randUppcase;
else
randAlpha = randLowcase;
myArray [i] = randAlpha;
|
My code:
myArray[i] = 'A' + rand()%26 + ( rand()%2 )*( 'a' - 'A' );