Hi,
I have recently completed a bubble sort array program, which works fine. And is here :
#include <iostream>
#include <ctime>
using namespace std;
void bubbleSort(int Array[], const int arraySize)
{
for(int j = 0 ; j < arraySize; j++)
{
for(int number = j + 1; number < arraySize; number++)
{
if(Array[j] > Array[number]) // swap if bigger
swap(Array[j],Array[number]);
}
}
}
void print(int Array[], const int size)
{
for(int i = 0; i < size; i++)
cout << Array[i] << " ";
cout<<endl<<endl;
}
int main()
{
srand(unsigned(time(0)));
int ArrayOne[10] = {0};
//populate with random numbers
for(int i = 0; i < 10; i++){
ArrayOne[i] = rand() % 100;
}
cout<<"Unsorted array : ";
print(ArrayOne,10);
cout<<"After being sortedt : ";
bubbleSort(ArrayOne,10);
print(ArrayOne,10);
return 0;
}
Basically as an extension of the task we have to dynamically allocate the array, and take in a value from the user for the size of the array.
I know that this would involve
int n = 0;
int* ArrayOne = NULL;
cout << "Please enter number of items: ";
cin >> n;
delete[] Array One
But im having trouble implementing this into my original program.
Any pointers/help would be greatly appreciated.