First off thanks to Prelude for help with the array itself. It was much appreciated. My question is, when you have a randomly generated dynamic array do you have to go about sorting in a different way than has been described by the countless posts and and googles searches I have browesed, because every one I try to incorporate into my code doesnt seem to work, I just need a little direction. Thanks for your time.
Code:
//------------------------Preprocessor Directives-----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
//-------------------------FunctioINDEX Prototypes--------------------------------------
int getstevesort(int *wNum);
int getdisplayResults(int largest, int smallest);
int getsmallest(int *wNum);
int getLargest( int*wNum);
int getMiddle(int *wNum);
//----------------------------Function Main----------------------------------------------
int main(void)
{
//-----------------------------Variable Declaration----------------------------------
int *wNum;
int stevesort;
int largest;
int smallest;
int i;
//int middle;
clrscr();
printf("EC03SRS996\n");
srand ( (unsigned)time ( NULL ) );
if ( ( wNum = malloc ( 11 * sizeof *wNum ) ) != NULL )
printf("Unsorted\n");
{
for ( i = 0; i < 11; i++ )
{
wNum[i] = ( rand() * 50 )/ RAND_MAX ;
printf(" %d\n",wNum[i]);
}
smallest = getsmallest(wNum);
largest = getLargest(wNum);
getdisplayResults(smallest,largest);
stevesort = getstevesort(wNum);
printf(" %d", wNum);
free ( wNum );
}
getch();
return 0;
}
//----------------------------End of Function Main--------------------------------------------
//-----------------------------userdefinition of getsort--------------------------------------
int getstevesort(int *wNum)
{
int n = 11;
int counter;
int pWalk = wNum + 1;
int pLook = wNum;
int pLast = &wNum + 10;
int temp;
for(counter = 0;counter < n; counter++);
{
if(pWalk <= pLook)
{
temp = pLook;
pLook = pWalk;
pWalk = temp;
pWalk++;
}
if(pWalk > pLook)
{
pWalk++;
}
if(pLast = &pWalk)
{
pLook++;
pWalk = pLook + 1;
counter = n - 1;
}
}
return wNum;
}
int getdisplayResults(int smallest, int largest)
{
printf("The smallest number is %d and the largest number is %d", smallest, largest);
return getdisplayResults;
}
//-------------------------User definition of getsmallest-------------------------------------
int getsmallest(int *wNum)
{
int *pLast;
int *pSmallest;
int *pWalk;
pLast = wNum + 10;
for (pSmallest = wNum, pWalk = wNum +1; pWalk <= pLast;pWalk++)
if (*pWalk < *pSmallest)
pSmallest = pWalk;
return *pSmallest;
}
//------------------------User definition of getlargest----------------------------------------
int getLargest(int *wNum)
{
int *pLargest;
int *pLast;
int *pWalk;
pLast = wNum + 10;
for (pLargest = wNum, pWalk = wNum +1; pWalk <= pLast;pWalk++)
if (*pWalk > *pLargest)
{pLargest = pWalk;
}
return (*pLargest);
}
//---------------------User definition of getMiddle---------------------------------------------