Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C#, please Lab8A: For this part of the lab, refer to the lecture slides for a review of Bubble Sort. Practice re-coding the program given

C#,image text in transcribed please

Lab8A: For this part of the lab, refer to the lecture slides for a review of Bubble Sort. Practice re-coding the program given in lecture. Write a program that prompts the user to enter 10 numbers and stores the input in a 1D array of size 10. Now, use Bubble Sort to sort the arraycontinuously pushing the largest elements to the right side of the array. Every time you swap two elements in the array, you need to increment a counter. After the inner loop has completed, you need to print out the current state of the array and the total number of swaps that have occurred. The sample outputs are shown below and the user input is in bold. Note: Sample output #1 shows the worst case scenario because it has the maximum number of swaps possible. Sample output #2 shows the average scenario because it has approximately half the number of swaps. Sample output #1 Enter slot 0: 10 Enter slot 1: 9 Enter slot 2: 8 Enter slot 3: 7 Enter slot 4: 6 Enter slot 5: 5 Enter slot 6: 4 Enter slot 7: 3 Enter slot 8: 2 Enter slot 9: 1 918171615|4|32|1|10| Num swaps: 9 8171615143121910Num swaps: 17 7165|43|2|1|89|10| Num swaps: 24 615143121718910| Num swaps: 30 5|43|2|1|67|89|10| Num swaps: 35 413|2|1|516171819|10| Num swaps: 39 312|1|451617189|10Num swaps: 42 2111314151617189|10| Num swaps: 44 112131415161718910| Num swaps: 45 112131415161718910Num swaps: 45 Sample output #2 Enter slot 0 : 5 Enter slot 1: 10 Enter slot 2: 8 Enter slot 3: 2 Enter slot 4: 1 Enter slot 5: 6 Enter slot 6: 7 Enter slot 7: 3 Enter slot 8: 9 Enter slot 9: 4 58|2|16|7139|4|10| Num swaps: 8 51216171318|49|10Num swaps: 14 21115161317148 910 Num swaps: 18 1|251316471819|10| Num swaps: 21 1|2|35|4|6171819|10| Num swaps: 23 1121314151617181910 Num swaps: 24 112131415161718 910 Num swaps: 24 11213141516171819|10| Num swaps: 24 11213141516171819|10| Num swaps: 24 11213141516171819|10| Num swaps: 24

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago