Here is my updated quicksort code. I am getting 29 errors when I try to compile it and i don't know what to do...I'll also post the list of errors
CODE
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:4: parse error before `*'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:11: parse error before `inputArray'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c: In function `QuickSort':
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:13: `myLength' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:13: (Each undeclared identifier is reported only once
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:13: for each function it appears in.)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:14: `inputArray' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:21: request for member `length' in something not a structure or union
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:43: invalid type argument of `unary *'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:44: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:50: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:55: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:63: `med' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:64: `temp' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:72: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:74: `i' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:74: `j' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:79: `medo30' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:79: parse error before `{'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:89: parse error before `else'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:106: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:108: `h' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:110: `smallerArray' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:119: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:121: parse error before `int'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:125: `k' undeclared (first use in this function)
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c: At top level:
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:128: parse error before `.'
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:128: warning: data definition has no type or storage class
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:132: `k' used prior to declaration
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:132: warning: data definition has no type or storage class
c:\docume~1\default\mydocu~1\visual~1\projects\quicks~1.c:133: parse error before `while'
And here is my programming code:
CODE
#include<stdio.h>
int main ();
void QuickSort (int[] *inputArray, int myLength);
int main ()
{
}
void QuickSort(int[] inputArray, int myLength)
{
int length = myLength;
int myArray[] = inputArray;
//
//Makes sure that quicksort won't try to do median of 3 with less than three
//characters, and sorts the arrays.
//
if (length <= 2)
{
if (myArray.length = 2)
{
if (myArray[0] > myArray[1])
{
int temp = myArray [0];
myArray[0] = myArray[1];
myArray[1] = temp;
}
}
}
else
{
//
//Determines median of three numbers (with those numbers being the first,
//last, and center numbers in the array.
//
int medo3;
int mid = (length/2);
if ((myArray[0] < myArray[length] && myArray[0] > myArray[mid]) || //determines if myArray[0]
(myArray[0] > myArray[length] && myArray[0] < myArray[mid])) //is median
{
medo3 = *myArray[0];
int med = 0;
}
else if ((myArray[length] < myArray[0] && myArray[length] > myArray[mid]) ||//determines if myArray[length]
(myArray[length] > myArray[0] && myArray[length] < myArray[mid])) //is median
{
medo3 = myArray[length];
int med = length;
}
else //establishes myArray[mid] as
{ //median if the values at 0
medo3 = myArray[mid]; //and length are not
int med = length;
}
//
//Swaps the median number with the number at the end so it doesn't get
//sorted.
//
int temp = myArray [med];
myArray[med]=myArray[length-1];
myArray[length-1]=temp;
//
//"i" moves from 0 up the array and stops on number that are greater than
//the median. "j" moves down the array from the number below the median and
//stops at numbers that are smaller than the median. When both i and j are
//stopped they swap.
//
int i = 0;
int j = 2;
while (i < j) //stops i and j from crossing so they don't
{ //resort the array
if (myArray[i] <= medo3)
{
if (myArray[j] >= medo30
{
temp = myArray[i]; //i and j swap
myArray[i] = myArray[j];
myArray[j] = temp;
}
else //j moves down if not on correct value
{
j--;
}
}
else //i moves up if not on correct value
{
i++;
}
//
//swaps the median with the value at i so that everything below the
//median is lower than it and vice versa
//
temp = myArray[i];
myArray[i] = myArray[length-1];
myArray[length-1] = temp;
//
//Creates array for the elements smaller than the median to be placed
//into so they can be passed into the recursive call of quicksort
//
int smallerArray[i-1];
int h = 0;
while (h < i)
{
smallerArray[h] = myArray[h];
h++;
}
QuickSort( smallerArray, i);
//
//Creates array for the elements smaller than the median to be placed
//into so they can be passed into the recursive call of quicksort
//
int largerArray[length-i];
h = i;
int k = 0
while (h < largerArray.length-1 && i < length+1)
{
largerArray[k] = *myArray[i+1];
k++;
i++;
}
Quicksort( largerArray, largerArray.length);
//
//Adds the sorted smaller list to the beginning of *myArray
//
k = 0;
while (k < smallerArray.length)
{
myArray[k] = smallerArray[k];
k++;
}
//
//Adds the sorted larger list to the end of *myArray after the median.
//
k++; //moves k to index after median
while (k < length)
{
myArray[k] = largerArray[k];
k++;
}
}
}
}
This post has been edited by Irishancest: 4 Dec, 2007 - 07:14 AM