The premise is to run BubbleSort with a small array size of 10, a medium size of 1000, and a large size of 10,000, and to see how long it took, in milliseconds (elapsed time).
Lines 23,38,53: You're trying to define myArray 3 different times in the same scope (main). I suggest you break your program into three functions.
edit: Lines 10-12: You don't need to declare bubbleSort 3 times. All three lines are identical to the compiler. The name of the argument makes no difference in a declaration.
When you say something "doesn't compile", please post the exact error messages from your compiler.
Lines 22 and 33 are declarations, not function calls. They don't do anythying other than tell the compiler how the respective functions should be called.
Your implementations at lines 67 and 73 don't match the declarations nor do they call bubbleSort.
myArray has disappeared. You haven't defined it anywhere.
@AbstractionAnon
Can you show me how to make these corrections please for my future knowledge in programming? I'm not quite sure how to fix those mistakes. Thank you.
I could show you how do do it, but you will learn more if you try and do it yourself. I've told you what's wrong. Fix those errors and post your new code. We will go from there.
You could probably begin with whatever resource(s) you're using to learn. I'm sure one of them tells you how to invoke functions. If not find yourself some new resources.
If you wish to call the function yes. Right now you are just prototyping and not calling them. Generally you prototype beneath your includes. To call a function you don't give a return type and you want to actually pass the parameters. Anyways your prototypes don't match the functions you declared later on.
You aren't declaring an array, you are passing it. So you would simply put myArray. Anyways, I don't think you understand functions and should read the link cire mentioned. The parameters are local to the function so when you pass a to function b it is now variable c not a. You should just use one bubble sort function and pass the size and not have different ones for different sizes that have the same inside. That would make functions pointless.
void bubbleSort(int array[], int size); //function prototype/definition
void bubbleSort(int [], int); //alternative function prototype
void bubbleSort(int *, int); //alternative function prototype
bubbleSort(someArray, someSize); //function call
void bubbleSort(int array[], int size) //names don't need to match prototype
//but these are the variable names being used in the function
{
//bubble sort here
}
//now to generate arrays:
void fillArray(int array[], int size); //prototype, I prefer to give names so I know what the parms are
fillArray(someArray, sizeOfArray); //function call
void fillArray(int array[], int size) //function declaration, you can use constant for size but must match prototype
{
for(int i = 0; i < size; ++i)
array[i] = rand();
}
This is what I have now. It still isn't compiling. What am I doing wrong?
You begin discovering what is wrong by paying attention to the output generated by your compiler when it fails to compile something. What does your compiler have to say?