LAB 8.3 Working with Sorts Bring in either the program bubble_sort.cpp or selection_sort.cpp from the Lab 8 folder. These are Sample Programs 8.3 and 8.4, respectively, from the Pre- lab Reading Assignment. The code for both are given below. // This program uses a bubble sort to arrange an array of integers in // ascending order // PLACE YOUR NAME HERE #include using namespace std; // function prototypes void bubbleSortArray (int [], int); void displayArray (int[], int); const int SIZE = 5; int main() int values [SIZE] (9,2,0,11,5); cout << "The values before the bubble sort is performed are:" << endl; displayArray (values, SIZE); bubbleSortArray(values, SIZE); cout << "The values after the bubble sort is performed are:" << er displayArray (valves, SIZE); return 0; ........... displayArray // Cooki // data int // data outi to print the array the array to be printed, the array size попе void displayArray(int array[], int elens) ' // function heading // dioplays the array for (int count 0; count using namespace std; // function prototypes void selectionSortArray(int [], int); void displayArray (int(), int); const int SIZE - 5; int main() int values (SIZE) - (9,2,0,11,5); cout << "The values before the selection sort is performed are:" << endl; displayArray (values, SIZE); selectionSortArray (values, SIZE); cout << "The values after the selection sort is performed are:" << endl; displayArray (values, SIZE); return 0;

Introductory Circuit Analysis (13th Edition)
13th Edition
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:Robert L. Boylestad
Chapter1: Introduction
Section: Chapter Questions
Problem 1P: Visit your local library (at school or home) and describe the extent to which it provides literature...
icon
Related questions
Question

solve this

LAB 8.3 Working with Sorts
Bring in either the program bubble_sort.cpp or selection_sort.cpp from the
Lab 8 folder. These are Sample Programs 8.3 and 8.4, respectively, from the Pre-
lab Reading Assignment. The code for both are given below.
// This program uses a bubble sort to arrange an array of integers in
// ascending order
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
// function prototypes
void bubbleSortArray (int [], int);
void displayArray (int[], int);
const int SIZE = 5;
int main()
int values [SIZE]
(9,2,0,11,5);
cout << "The values before the bubble sort is performed are:" << endl;
displayArray (values, SIZE);
bubbleSortArray(values, SIZE);
cout << "The values after the bubble sort is performed are:" << er
displayArray (valves, SIZE);
return 0;
...........
displayArray
// Cooki
// data int
// data outi
to print the array
the array to be printed, the array size
попе
void displayArray(int array[], int elens)
'
// function heading
// dioplays the array
for (int count 0; count <elons; count++)
cout << array[count] <<<<< endl;
Transcribed Image Text:LAB 8.3 Working with Sorts Bring in either the program bubble_sort.cpp or selection_sort.cpp from the Lab 8 folder. These are Sample Programs 8.3 and 8.4, respectively, from the Pre- lab Reading Assignment. The code for both are given below. // This program uses a bubble sort to arrange an array of integers in // ascending order // PLACE YOUR NAME HERE #include <iostream> using namespace std; // function prototypes void bubbleSortArray (int [], int); void displayArray (int[], int); const int SIZE = 5; int main() int values [SIZE] (9,2,0,11,5); cout << "The values before the bubble sort is performed are:" << endl; displayArray (values, SIZE); bubbleSortArray(values, SIZE); cout << "The values after the bubble sort is performed are:" << er displayArray (valves, SIZE); return 0; ........... displayArray // Cooki // data int // data outi to print the array the array to be printed, the array size попе void displayArray(int array[], int elens) ' // function heading // dioplays the array for (int count 0; count <elons; count++) cout << array[count] <<<<< endl;
// data in:
// data out:
the array, the array size
the sorted array
void bubbleSortArray(int array[], int elems)
bool swap
int temp;
int bottom elems - 1;
// bottom indicates the end part of the..
// array where the largest values have
// settled in order
swap
false;
for (int count = 0; count <bottom; count++)
if (array[count] array[count+1])
// the next throo lines do a ovap
temp array[count];
array[count] array[count+1];
array[count+1]
tempe
Swap - true, // indicates that a awap occurred
bottom--
// bottom is decremented by 1 since each pass through
// the array adds one more value that is set in order
while (swap - false);
/ loop repeats until a pass, through the array with
77 no swaps occurs
selection sort.cpp
// This program uses a selection sort to arrange an array of integers in
// ascending order
//PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
// function prototypes
void selectionSortArray(int [], int);
void displayArray (int(), int);
const int SIZE - 5;
int main()
int values (SIZE) - (9,2,0,11,5);
cout << "The values before the selection sort is performed are:" << endl;
displayArray (values, SIZE);
selectionSortArray (values, SIZE);
cout << "The values after the selection sort is performed are:" << endl;
displayArray (values, SIZE);
return 0;
Transcribed Image Text:// data in: // data out: the array, the array size the sorted array void bubbleSortArray(int array[], int elems) bool swap int temp; int bottom elems - 1; // bottom indicates the end part of the.. // array where the largest values have // settled in order swap false; for (int count = 0; count <bottom; count++) if (array[count] array[count+1]) // the next throo lines do a ovap temp array[count]; array[count] array[count+1]; array[count+1] tempe Swap - true, // indicates that a awap occurred bottom-- // bottom is decremented by 1 since each pass through // the array adds one more value that is set in order while (swap - false); / loop repeats until a pass, through the array with 77 no swaps occurs selection sort.cpp // This program uses a selection sort to arrange an array of integers in // ascending order //PLACE YOUR NAME HERE #include <iostream> using namespace std; // function prototypes void selectionSortArray(int [], int); void displayArray (int(), int); const int SIZE - 5; int main() int values (SIZE) - (9,2,0,11,5); cout << "The values before the selection sort is performed are:" << endl; displayArray (values, SIZE); selectionSortArray (values, SIZE); cout << "The values after the selection sort is performed are:" << endl; displayArray (values, SIZE); return 0;
Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Introductory Circuit Analysis (13th Edition)
Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:
9780133923605
Author:
Robert L. Boylestad
Publisher:
PEARSON
Delmar's Standard Textbook Of Electricity
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:
9781337900348
Author:
Stephen L. Herman
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Electrical Engineering
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education
Fundamentals of Electric Circuits
Fundamentals of Electric Circuits
Electrical Engineering
ISBN:
9780078028229
Author:
Charles K Alexander, Matthew Sadiku
Publisher:
McGraw-Hill Education
Electric Circuits. (11th Edition)
Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:
9780134746968
Author:
James W. Nilsson, Susan Riedel
Publisher:
PEARSON
Engineering Electromagnetics
Engineering Electromagnetics
Electrical Engineering
ISBN:
9780078028151
Author:
Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:
Mcgraw-hill Education,