ok here is a snippets of my code and this is what I'am trying to do:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ARY_SIZE 50
//Function Declarations
void generNum (int* randNum);
void printNum (int* data, int numItems, int countPerLine);
void bubbleSort (int* randNum, int end);
int main (void)
{
//local Declarations
int randNum [ARY_SIZE];
//statements
//generate random numbers
generNum (randNum);
printNum (randNum, ARY_SIZE, 10);
bubbleSort (randNum, 49);
printNum (randNum, ARY_SIZE, 10);
system ("PAUSE");
return 0;
} //main
/*==============================generNum======================================
Generate random numbers that will be used to fill an array.
Pre: randNum array is to recieve the random numbers generated.
Post: filled array
*/
void generNum (int* randNum)
{
//local Declarations
int* aRandNo;
//statements
srand(time (NULL));
for (int i =0; i < ARY_SIZE; i++)
{
aRandNo = randNum+i;
*aRandNo = rand() % 999 + 1;
}//for
return;
}//generNum
/*===============================printNum=======================================
Prints the data of the array.
Pre: data- a filled array
last- last elements indicated by an index
countPerLIne: number of elements on a line
Post: data printed
*/
void printNum (int* data, int numItems, int countPerLine)
{
//Local Declarations
int elemPrinted = 0;
//Statements
printf ("\n");
for (int i = 0; i < numItems; i++)
{
elemPrinted++;
printf ("%3d ", *(data+i));
if (elemPrinted >= countPerLine)
{
printf ("\n");
elemPrinted = 0;
}//if
}//for
printf ("\n");
return;
} // printNum
/*=================================bubbleSort=================================
Sort array using bubble sort. Elements are compared and exchanged until list
is in order.
Pre: minimun of 1 random number.
end contains index of last element in randNum array.
Post: randNum array is rearranged in sequence low to high.
*/
void bubbleSort (int* randNum, int end)
{
//Local Declarations
int temp;
int* address;
//Statements
//outer Loop
for (int initial = 0; initial <= end; initial++)
{
//Inner loop. Bubble starts at end and moves up 1 element each pass.
for (int mover = end;
mover > initial;
mover--)
if (*(randNum +mover) < *(randNum +(mover - 1)))
{
temp = *(randNum +mover);
address = randNum +mover;
*address = *(randNum +(mover - 1));
address = randNum +(mover - 1);
*address = temp;
}//if - exchange of numbers
}//for initial
return;
} //bubblesort
/*===============================search========================================
Determine if the array is sorted or unsorted.
Pre: the array
Post: If sorted will search by binary method,
Else unsorted will search by sequential search
*/
this is just a portion of the code I have the menu else where. I am utterly unsure where to look to begin this next part of the code. I've attempted it from a variety of directions but obviously I'm confused.
Thanks