Hey all!
I am trying to write a program that allows for:
1.) The user to enter the SIZE of an array.
2.) Prints random element numbers.
3.) Saves the random element numbers printed in the array.
4.) Bubble sorts and then prints the randomly printed numbers.
Here is what I have so far:
#include <iostream>
using namespace std;
int * Array;
int SIZE = 0;
int n = 0;
void bubbleSort(int * Array,int SIZE)//Bubble sort function
{
int i,j;
for(i=0;i<SIZE;i++)
{
for(j=0;j<i;j++)
{
if(Array[i]>Array[j])
{
int temp=Array[i]; //swap
Array[i]=Array[j];
Array[j]=temp;
}
}
}
} //End bubbleSort function
int main()
{
cout << "Please enter the \"SIZE\" (number of Elements) you want for this array: " << endl ; // Prompt user for SIZE
cin >> SIZE; // Allow input of SIZE from user
cout << endl; // Print blank line
cout << "The \"SIZE\" (# of Elements) you have chosen for this array is: \"" << SIZE << "\" Elements." << endl ; //Print SIZE chosen to user
cout << endl; // Print blank line
cout << "Welcome to \"Array[" << SIZE << "]\"!" << endl; // Print welcome message
cout << endl; // Prints blank line
Array = new int[SIZE]; // Allocates memory for array
cout << "The \"unsorted\" random Elements for \"Array[" << SIZE << "]\" are as follows:..." << endl;
// Prints to user notification that the following is the unsorted Array SIZE elements
cout << endl; //Prints blank line
for(int i = 0; i < SIZE; i++)
{
Array[i] = i; // Array declaration, Array is equal to i
cout << "Array[" << n++ << "] " << rand() << endl; // Print SIZE random numbers in array[i]
}
cout << endl;
cout << "The \"sorted\" random Elements for \"Array[" << SIZE << "]\" are as follows:..." << endl;
// Prints to user notification that the following is the sorted Array SIZE elements
cout << endl;
bubbleSort(int * Array, int SIZE);
return 0; // Indicates success
}// End function main
Thank you!!!!