Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
For the sorting Choice, do the following:
Right after your header file and using namespace std;
int sortingChoice;
// Declare the functions
void SelectionSort(item Type A[], int N);
int Min(item Type A[], int i, int N);
void InsertionSort(item Type A[], int N);
void BubbleSort(item Type A[], int N);
In the main:
a)
Declare the array dynamically (this has been discussed in the class) using pointer
b) Allocate memory to N number of data
c)
Get user inputs (do not initialize the array) using cin statement to fill up the array for all N elements
d)
e)
Get the value for sortingChoice by properly prompting the user
Write a switch statement using sorting Choice as controlling parameter, and call SelectionSort for case 1,
InsertionSort for case 2, BubbleSort for case 3, and default case display an error message saying that the choice is
wrong.
Outside the switch statement, display the sorted array with proper title.
If you have forgotten how to use switch statement, use the following structure
switch(sorting Choice)
case 1:
SelectionSort(A, N);
{
break;
case 2:
InsertionSort(A, N);
break;
and so on
default:
cout << "Not a correct choice" << endl;
}
Then display the sorted array.
expand button
Transcribed Image Text:For the sorting Choice, do the following: Right after your header file and using namespace std; int sortingChoice; // Declare the functions void SelectionSort(item Type A[], int N); int Min(item Type A[], int i, int N); void InsertionSort(item Type A[], int N); void BubbleSort(item Type A[], int N); In the main: a) Declare the array dynamically (this has been discussed in the class) using pointer b) Allocate memory to N number of data c) Get user inputs (do not initialize the array) using cin statement to fill up the array for all N elements d) e) Get the value for sortingChoice by properly prompting the user Write a switch statement using sorting Choice as controlling parameter, and call SelectionSort for case 1, InsertionSort for case 2, BubbleSort for case 3, and default case display an error message saying that the choice is wrong. Outside the switch statement, display the sorted array with proper title. If you have forgotten how to use switch statement, use the following structure switch(sorting Choice) case 1: SelectionSort(A, N); { break; case 2: InsertionSort(A, N); break; and so on default: cout << "Not a correct choice" << endl; } Then display the sorted array.
Write a program that can implement (a) Selection sort (b) Insertion sort and (c) Bubble sort in the same program,
and main will call one of the methods depending on the value of sortingChoice (define this variable globally). If the
sortingChoice is 1, call Selection sort, if it is 2, call Insertion sort and if it is 3, call Bubble Sort.
You need to write 4 functions:
a) Selection sort and Min function that returns the minimum index
b)
Insertion Sort
c) Bubble Sort
expand button
Transcribed Image Text:Write a program that can implement (a) Selection sort (b) Insertion sort and (c) Bubble sort in the same program, and main will call one of the methods depending on the value of sortingChoice (define this variable globally). If the sortingChoice is 1, call Selection sort, if it is 2, call Insertion sort and if it is 3, call Bubble Sort. You need to write 4 functions: a) Selection sort and Min function that returns the minimum index b) Insertion Sort c) Bubble Sort
Expert Solution
Check Mark
Step 1

Algorithm:

1. Begin.

2. Declare sortingChoice, N, and A (an array).

3. Prompt the user to enter the number of elements and store it in N.

4. Prompt the user to enter the elements of the array and store it in A.

5. Prompt the user to enter the sorting choice.

6. Compare the sorting choice
    6a. If sortingChoice is 1, call SelectionSort().
    6b. If sortingChoice is 2, call InsertionSort().
    6c. If sortingChoice is 3, call BubbleSort().
    6d. Otherwise, display an error message.

7. After the sorting, display the sorted array.

8. Free the memory allocated for A.

9. End.

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education