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: 63% (11 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)
-
Brian gets paid $ 5 0 0 every Friday, but the month ended on Wednesday. How much will the company accrue for Brian's wages?
-
For the data in Table 12.1, confirm that the Pearson statistic in equation (12.3) is 41.98 . Table 12.1 (12.3) Count Observed (j) (nj) Fitted Counts Using the Poisson Distribution (np;) 01234 6,996...
-
A particular stock sells for $30. The stocks beta is 1.25, the risk-free rate is 4%, and the expected return on the market portfolio is 10%. If you forecast that the stock will be worth $33 next year...
-
Let (X,T) be a topological space, where A and B are subsets of X. Prove that (AUB)' A'U B'
-
Cesar Rego Computers, a Mississippi chain of computer hardware and software retail outlets, supplies both educational and commercial customers with memory and storage devices. It currently faces 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);....
-
Visit the websites of the IOC and the OCOG for the upcoming Summer or Winter Olympic Games and try to discover what kinds of security measures they are planning to implement.
-
You have bought on margin 100 zero-coupon bonds, with face value \( 1000\), maturing in three years. At present, the annual yield (annual return with annual compounding) of the bonds is \(4.3 \%\)....
-
You hold a long position in an asset, whose price is correlated with two commodity prices. The two commodities are the underlying assets of two futures contracts maturing at time \(T_{F}\). There is...
-
Which company has the lowest accounts receivable turnover in the year 20X2? A. Company A. B. Company B. C. Company D. Mary Gonzales is evaluating companies in the office supply industry and has...
-
The industry average receivables collection period: A. increased from 20X1 to 20X2. B. decreased from 20X1 to 20X2. C. did not change from 20X1 to 20X2. Mary Gonzales is evaluating companies in the...
-
Using vertical common-size analysis of the income statement of Tab for 2005, the cost of sales relative to the benchmark is closest to: A. 75%. B. 80%. C. 85%. Tab, Inc., Income Statements for Fiscal...
-
On June 1, 2012, Skylark Enterprises (not a corporation) acquired a retail store building for $500,000 (with $100,000 being allocated to the land). The store building was 39-year real property, and...
-
Refer to the information from Exercise 22-19. Use the information to determine the (1) Weighted average contribution margin , (2) Break-even point in units, and (3) Number of units of each product...
-
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
-
Question: Part One: Memo Write an analysis of the impact of tax laws and incentives as demonstrated in this current years tax return. Specifically, you must address the following: Explain the...
-
From the following ledger balances, prepare a trial balance for the Cheyenne Corp. at June 3 0 , 2 0 2 2 . All account balances are normal.Accounts Payable $ 1 0 , 0 0 0 , Cash $ 7 , 4 0 0 , Common...
-
Kathy is mixing fruit punch in a 32-cup punch bowl for a party. She plans to add at least 20 cups of fruit juice to the bowl before adding ginger ale. Identify the graph that represents the amounts...
Study smarter with the SolutionInn App