Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions