Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write two C++ functions bubblesort() and cocktailsort(), given a text file numbers.txt that contains 20 positive integers unsorted. Write a program that reads the numbers
Write two C++ functions bubblesort() and cocktailsort(), given a text file numbers.txt that contains 20 positive integers unsorted.
Write a program that reads the numbers from the provided file and then displays them in the Console Window is ascending order, using both the bubble sort and the cocktail sort method. Your program should include at least two functions: one for the bubble sort algorithm, one for the cocktail sort algorithm. Note: You might also want to write and use a function that swaps two values. You also need to display the number of comparisons and the number of swaps executed by each method. Your output in the Console Window should look like this: Bubble Sort 1 1 2 3 3 3 3 4 4 5 6 7 7 7 8 9 10 13 15 17 Number of Comparisons Number of swaps Cocktail Sort 1 1 2 3 3 3 3 4 4 5 6 7 7 7 8 9 10 13 15 17 Number of Comparisons Number of swapsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started