C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 16, Problem 5SA
Program Plan Intro
Program Plan:
- Include the necessary header files: iostream and
vector . - Define the bubbleSort function that takes a reference to a vector of integers.
- Inside the bubbleSort function, implement the bubble sort
algorithm using nested loops: - Inside the main function:
- Create a vector of integers arr and initialize it with the given values.
- Call the bubbleSort function to sort the vector.
- Display the sorted vector using a for loop.
Program Description:
To sort the list using the bubble sort algorithm and display the list after each iteration of the outer for loop.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
sortSequence(sequence):
loop forever:
choose any two values in the sequence at random
swap the two values if the sequence is sorted:
return (i.e., leave this function)
Is this algorithm correct? is it capable of taking any sequence of values and sorting it?
Given this array:
Sorting smallest to largest, draw this array after:
a) Two iterations of Bubble Sort
b) Two iterations of the outer (big) loop of Selection Sort
c) Two iterations of the outer (big) loop Insertion Sort
7. Perform Selection Sort on the following numbers.
10
90
18
23
56
92
42
33
Show all intermediate steps.
Chapter 16 Solutions
C++ Programming: From Problem Analysis to Program Design
Knowledge Booster
Similar questions
- Given the list A= {13, 27, 37, 59, 73, 98, 125, 178, 194, 214, 235, 263, 271, 342, 365, 380, 401, 433, 460, 477} a) Show the required steps to search 200 using jump search with best jump value b) Show the required steps to search 200 using interpolation searcharrow_forwardSorting refers to arranging data in a particular order. Apply Bubble Sort algorithm to sort the given list of numbers in descending order. Show the results of each round of the bubble sort algorithm. 27 59 81 62 35 56 31 23 6.arrow_forwardplease step by step no code Sort the list A , L , G , O , R , I , T , H , A , M in alphabetical order by Bubble sortarrow_forward
- Sort the following list using the Selection Sort algorithm . Show the list after each iteration of the outer for loop (after each complete pass through the list) IMPORTANT: Separate each value by a comma and only one space after each comma and no space after the last value. You will have seven iterations of the list for your answer. 38, 60, 43, 5, 70, 58, 15, 10arrow_forwardSort the following lists using the Bubble Sort algorithm provide Step-by-step answers? a) Original list: [5, 2, 8, 1,6] b) Original list: [8, 3, 1, 5, 4]arrow_forwardGiven the unsorted list [6, 5, 4, 3, 7, 1, 2], show what the contents of the listwould be after each iteration of the loop as it is sorted using the following:a. Selection sortb. Insertion sortarrow_forward
- Recursive Binary Search Instructions The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version of the binary search algorithm. The program should prompt Y / y to continue searching and N / n to discontinue. If an item is found in the list display the following message: x found at position y else: x is not in the list Use the following list of integers when testing your program: 2, 6, 8, 13, 25, 33, 39, 42, 53, 58, 61, 68, 71, 84, 97arrow_forwardUse the following array to show the operation of the selection sort in ascending order. Show the list after each swap. 5 8. 1 4arrow_forwardPlease match each question with its best answer. Answers may be used more than once. Question Selected Match Uses both a do-while loop and a for loop G Bubble sort Probably makes fewer swaps to sort an array F Selection Sort Uses nested loops D Both bubble sort and selection sort Compares side by side elements to see if they need to swap H. Sequential sort Can sort Strings, chars, doubles, and ints D Both bubble sort and selection sort When sorting in ascending order, the smallest element is put into place first D Both bubble sort and selection sort When sorting in ascending order, the largest element is put into place first A Neither Bubble Sort nor Selection Sortarrow_forward
- 8. Sort the following set of integers from smallest to largest using either an insertion sort or a selection sort (indicate CLEARLY which sort you are performing). Show the entire set of numbers after each step of the sort algorithm has completed (a total of 8 pictures): 10, 20, 5, 7, 12, 40, 8, 11arrow_forwardShow how the Selection Sort works on this list array to sort it in ascending order. 55 35 20 80 90 40 60 95 10 75arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage