Draw a flowchart for the bubble sort program shown in Figure 11-34. 1 //Bubble Sort.cpp - uses
Question:
Draw a flowchart for the bubble sort program shown in Figure 11-34.
Transcribed Image Text:
1 //Bubble Sort.cpp - uses the bubble sort to sort the 2 //contents of a one-dimensional array in ascending order 3 //Created/revised by
1 //Bubble Sort.cpp - uses the bubble sort to sort the 2 //contents of a one-dimensional array in ascending order 3 //Created/revised by on 4 5 #include 6 using namespace std; 7 8 int main() 9 { int numbers[4] {23, 46, 12, 35}; int sub = 0; int temp = 0; int maxSub - 3; int lastSwap = 0; char swap = 'Y'; 10 11 //keeps track of subscripts //variable used for swapping //maximum subscript 7/position of last swap /indicates if a swap was made 12 13 15 16 //repeat loop instructions as long as a swap was made while (swap =- 'Y') 17 18 19 20 Swap = 'N'; //assume no swaps are necessary 21 //begin comparing with first //array element 22 sub - 0; 24 25 //compare adjacent array elements to determine //whether a swap is necessary while (sub < maxSub) 26 27 28 if (numbers[sub] > numbers [sub + 1]) { //a swap is necessary temp = numbers [sub]; numbers [sub] = numbers [sub + 1]; numbers [sub + 1] = temp; swap = 'Y'; lastSwap = sub; } //end if sub += 1; //increment subscript } //end while 29 30 31 32 33 36 37 38 39 40 41 maxSub = lastSwap; //reset maximum subscript 42 } //end while //display sorted array for (int x = 0; x < 4; x += 1) cout « numbers[x] << endl; //end for return 0; 45 46 47 48 49 } //end of main function Figure 11-34 Bubble sort program 111 L1 2~2 2~ 333 333 44 444 44
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 73% (15 reviews)
O M 1 F stop 4 F start assign 0 to sub temp and lastSwap ass...View the full answer
Answered By
Ajay Negi
Hi, I've completed my degree in engineering (Information Technology) from an NIT. Currently working as a software engineer. Wish to impart quality education to the future generation.
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell
Question Posted:
Students also viewed these Computer science questions
-
Write a program that obtains the execution time of selection sort, bubble sort, merge sort, quick sort, heap sort, and radix sort for input size 50,000, 100,000, 150,000, 200,000, 250,000, and...
-
Write an animation for selection sort, insertion sort, and bubble sort, as shown in Figure 30.31. Create an array of integers 1, 2, . . . , 50. Shuffle it randomly. Create a pane to display the array...
-
Write a program that animates the bubble sort algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as shown...
-
Prepare a personal SWOT analysis (Your personal Strengths and Weaknesses and the external macroeconomic Opportunities and Threats that all of your competitors will assess criteria examples Advantages...
-
Let f(x,y) = ex + 2ey + 3xy2 + 1. (A)Use graphical approximation methods to find d (to three decimal places) such that f(l,d) is the minimum value of fix, y)when x = 1. (B) Find fx(l,d) and fy,(l,d)
-
19.11A Fallon Frodsham Limited manufactures and installs small prefabricated building structures that are sold to people who want to establish a home office using part of their gardens. Each...
-
Sun safety study. Excessive exposure to solar radiation is known to increase the risk of developing skin cancer, yet many people do not practice sun safety. A group of University of Arizona...
-
A recent poll asked 16- to 21-year-olds whether or not they are likely to serve in the U.S. military. The following table, cross-classified by gender and race, reports the percentage of those polled...
-
Question 8 (1 point) Saved Normal spoilage rates for a manufacturing process should be computed on the basis of total actual units. total actual units minus total reworked units. total reworked...
-
Given the plaintext [0001 0203 0405 0607 0809 0A0B 0C0D 0E0F] and the key [0101 0101 0101 0101 0101 0101 0101 0101] a. Show the original contents of state, displayed as a 4x4 matrix. b. Show the...
-
Rewrite the code from Pencil and Paper Exercise 13 using the for statement. Data From Exercise 13 Write the code to display the smallest number stored in a one-dimensional int array named orders. The...
-
The numbers array is a five-element one-dimensional int array. The following statement should display the result of raising the first array element to the second power: cout < < pow(nums[0], 2);....
-
In futures markets, profits or losses on contracts are settled at the end of each trading day. This procedure is called marking to market or daily resettlement. By preventing a trader's losses from...
-
Indicate whether each of the following types of transactions will either (a) increase stockholders' equity or (b) decrease stockholders' equity: 1. expenses 2. revenues 3. stockholders' investments...
-
The following selected transactions were completed by Lindbergh Delivery Service during October: 1. Received cash from issuing capital stock, \($75,000\). 2. Paid rent for October, \($4,200\). 3....
-
Murray Kiser operates his own catering service. Summary financial data for February are presented in equation form as follows. Each line designated by a number indicates the effect of a transaction...
-
A. Given that y = e 2x + 1 complete the table of values of y corresponding to x = 0.5, 1 and 1.5. B. Use the trapezium rule, with all the values of y in the completed table, to obtain an estimate for...
-
Draw a schematic using NFETs and PFETs for a restoring logic gate that implements the function = 0 if zero or two of inputs cba are true. Assume that all inputs and their complements are available.
-
Explain why a territorial tax law could encourage U.S.-based MNCs to consider moving their headquarters to another country.
-
What is an access control list?
-
In the following pseudocode, what percentage raise will an employee in Department 10 receive? if department < 2 then raise = SMALL_RAISE else if department < 6 then raise = MEDIUM_RAISE else if...
-
In the following pseudocode, what percentage raise will an employee in Department 10 receive? if department < 2 then raise = SMALL_RAISE else if department < 6 then raise = MEDIUM_RAISE else if...
-
When you use a range check, you always compare a variable to ______________ value in the range. a. The lowest b. The highest c. An end-of-range value d. The average
-
Sociology
-
I am unsure how to answer question e as there are two variable changes. In each of the following, you are given two options with selected parameters. In each case, assume the risk-free rate is 6% and...
-
On January 1, Interworks paid a contractor to construct a new cell tower at a cost of $850,000. The tower had an estimated useful life of ten years and a salvage value of $100,000. Interworks...
Study smarter with the SolutionInn App