sorting and copying array

Okay it looks like a copied the initial random numbers, but unable to sort it for some reason i couldn't figure it out. Im not sure if my for loop is working properly.

#include<iostream>
#include<cstdlib>
#include<ctime>

//function prototype
void initialize_array(int [],int);//to initialize an array
int *sort_array(int [],int);//to sort the array
void print_array(int [],int);//to display the unsorted and sorted array

using namespace std;

int main()
{
int *array1 = nullptr;//To point to the numbers
int *array2 = nullptr;


int num1;//declare a variable

//ask the user for the amount of integer numbers
cout<<"Enter the amount of integer numbers: ";
cin>>num1;

//dynamically allocate the array
array1 = new int[num1];
array2 = new int[num1];


//call function to initialize the arrays
initialize_array(array1,num1);
initialize_array(array2,num1);


//call function to display unsorted random numbers
cout<<"\n\n the initial array with random numbers are\n";
print_array(array1,num1);

for(int x=0;x<num1; x++)
{
array1[x]=array2[x];
}

//call function to display sorted random numbers
cout<<"\n\n the output random numbers are\n";
sort_array(array2,num1);



//free the memory
delete []array1;
delete []array2;
array1 = 0;
array2 = 0;
return 0;
}

//to display the array
void print_array(int array[],int size)
{
for(int x = 0; x < size; x++)
{
cout<<array[x]<<" ";
}
cout<<endl;
}
//to initialize the array
void initialize_array(int array[],int num)
{
//initialize the array filling it out with random number 1-100
srand(time(0));
for(int x = 0; x < num; x++)
array[x] = rand()%100 + 1;
}
//to sort the array using bubble sort
int *sort_array(int array[],int size)
{
int *newArray=nullptr;
newArray=new int[size];
for(int z=0; z<size; z++)
{
newArray[z]=array[z];
int a,x,y,w;
for(x = 0; x < size-1; x++)
{
y=x;
w=newArray[x];
for(a = x+1; a < size; a++)
{
if(newArray[a]<w)
{
w=newArray[a];
y=a;
}
}
newArray[y]=newArray[x];
newArray[x]=w;

}
cout<<newArray[z]<<" ";

}
cout<<endl;


return array;
}
okay it looks like the random numbers are sorted out -----> solved
but next problem is to find the pivot point or number and then split one array into two arrays not including the pivot number. Any suggestion is greatly appreciated
Registered users can post here. Sign in or register to post.