Question: Given the following class, Please complete the class implementation and write a main function to test the class. class sorting _ algorithms { public: sorting

Given the following class, Please complete the class implementation and write a main function to test the class.
class sorting_algorithms
{
public:
sorting_algorithms(); //constructor
void initialize(); //get the list size from the user and then fill the list with random numbers
//between 1 and 1000
void print_list(int*); //print list contents
void bubble_sort();//perform Bubble sort algorithm
void insertion_sort();//perform insertion sort algorithm
void selection_sort(); //perform selection sort algorithm
private:
int *list0,*list1,*list2; //lists are for bubble, insertion, and select sort
int len;
};
Your main function may look like:
int main()
{
sorting_algorithms mine;
mine.intitialize(); //get list length and initialize the needed lists. This function is given.
mine.print_list(list0);
mine.bubble_sort();
mine.insertion_sort();
mine.selection_sort();
mine.print_list(list0); //print the list sorted by bubble sort
mine.print_list(list1);//print the list sorted by insertion sort
mine.print_list(list2);//print the list sorted by selection sort
return 0;
}
void sorting_algorithms::initialize()
{
cout<<
Enter list size: ;
cin >> n;
list0= new int[n]; //memory allocation to pointer list0
list1= new int[n]; //memory allocation to pointer list1
list2= new int[n]; //memory allocation to pointer list2
for (int i =0; i < n; i++)
{
list0[i]= rand()%1000+1; //between 1 and 1000 for bubble sort
list1[i]=list2[i]= list0[i];//make two copies for other sorting algorithms
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!