Trying to write a code so that I'm not changing the original array. Just sorting in ascending order and then in descending order. I have lost my train of thought and am now stuck.
Could some body help walk me throught this. Need help please.
Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
//Function Declarations
int* getData (int* pAry, int arySize);
void bubbleSortAscend (int* pAry, int* last);
void bubbleSortDescend (int* pAry, int* last);
void printData (int* pAry, int* last);
int* smallest (int* pAry, int* pLast);
void exchange (int* current, int* smallest);
int main (void)
{
// Local Declarations
int ary[SIZE];
int* pLast;
// Statements
pLast = getData (ary, SIZE);
bubbleSortAscend (ary, pLast);
bubbleSortDescend (ary, pLast);
printData (ary, pLast);
system("PAUSE");
return 0;
}//main
/*============================getData=======================================
Reads data from keyboard into array for sorting.
Pre pAry is pointer to array to be filled
arySize is integer with maximum array size
Post array filled. Returns address of last element
*/
int* getData (int* pAry, int arySize)
{
//Local Declarations
int ioResult;
int readCnt = 0;
int* pFill = pAry;
// Statements
do
{
printf ("Please enter number of <EOF>: ");
ioResult = scanf ("%d", pFill);
if (ioResult == 1)
{
pFill++;
readCnt++;
}//if
}while (ioResult == 1 && readCnt < arySize);
printf ("\n\n%d numbers read.", readCnt);
return (--pFill);
} // getData
/*=========================bubbleSortAscend===============================
Sorts a list using bubble sort. Adjacent elements are compared and
exchanged until list is ordered.
Pre the list must contain contain at least one item
last contains index to last element to list
Post list rearranged in sequence low to high
*/
void bubbleSort(int* pAry, int* last)
{
//Local Declarations
int temp;
//Statements
//Outer loop
for (int current = 0; current < *last; current++)
{
//Inner Loop: Bubble up one element each pass
for (int walker = *last;
walker > current;
walker--)
if (list[walker] < list[walker-1])
{
temp = list[walker];
list[walker] = list[walker - 1];
list[walker - 1] = temp;
}//if
}// for current
return;
} // bubbleSortAscend
/*=============================bubbleSortDescend===============================
*/
void bubbleSortDescend(int* pAry, int* last)
{
//Local Declarations
int temp2;
//Statements
//Outer loop
for (int current = 0; current < *last; current++)
{
//Inner Loop: Bubble up one element each pass
for (int walker = *last;
walker > current;
walker--)
if (list[walker] < list[walker-1])
{
temp2 = list[walker];
list[walker] = list[walker - 1];
list[walker - 1] = temp2;
}//if
}// for current
return;
} // bubbleSortDescend
I appreciate any help. Thank you!!!!