GENERAL ENGINEERING Perform the following data structure on Sorting: BASIC PROGRAMMING CREATE an array with at least 5 in size and put elements in the array. Perform the following: Sorting Data Structure operation: 1. Bubble Sort 2. Insertion Sort 3. Selection Sort CHOOSE OPERATION : // if option 1 is selected, sort the elements of the array using Bubble sort: //if option 2 is selected, sort the elements of the array using Insertion sort: //if option 3 is selected, sort the elements of the array using Selection sort: BubbleSort.java import java.util.*; class BubbleSort{ 1 InsertionSort.java // Driver method to test above public static void main(String args[]) { I/declare an array of integers int intarray[] {23,43,13,65,11,62,76,83,9,71,84,34,96,80}; I/print original array System.out.println("Original array: " + Arrays.toString(intArray)); int n = intArray.length; //iterate over the array comparing adjacent elements for (int i = e; i < n-1; i++) for (int j = 0; j =0 && temp <= numArray[j]) 4 3 6 4 5 8. 6 9 10 { 11 9 12 10 //if elements not in order, swap them if (intArray[j] > intArray[j+1]) { int temp - intArray[j]; intArray[j] - intArray[j+1]; intArray[j+1] - temp; 13 11 { 14 12 numArray[j+1] = numArray[j]; 15 13 j- j-1; 16 14 17 15 numArray[j+1] - temp; 18 } 16 //print the sorted array System.out.println("Sorted array: } 19 I/print the sorted array System.out.println("Sorted Array:" + Arrays.tostring(numArray)): } } 17 20 + Arrays.toString(intArray)); 18 21 19 22 20 SelectionSort.java 1 import java.util.*; class SelectionSort { static void sel_sort(int numArray[]) 3 4 5 6 int n = numArray.length; // traverse unsorted array for (int i = e; i < n-1; i++) { // Find the minimum element in unsorted array 8 9 10 11 int min_idx i; for (int j = i+1; j < n; j++) if (numArray[j] < numArray[min_idx]) min_idx = j; 12 13 14 15 16 // swap minimum element with compared element int temp = numArray[min_idx]; numArray[min_idx] = numArray[i]; numArray[i] = temp; 17 18 19 20 21 22 } 23 public static void main(String args[]) { //declare and print the original array 24 25 26 int numArray[] {8,4,1,15,52,12,32,11,23}; System.out.println("Original Array:" + Arrays.tostring(numArray)) 27 28 29 //call selection sort routine sel_sort(numArray); I/print the sorted array System.out.printin("Sorted Array:" + Arrays.tostring(numArray)); 30 31 32 33 34 }
GENERAL ENGINEERING Perform the following data structure on Sorting: BASIC PROGRAMMING CREATE an array with at least 5 in size and put elements in the array. Perform the following: Sorting Data Structure operation: 1. Bubble Sort 2. Insertion Sort 3. Selection Sort CHOOSE OPERATION : // if option 1 is selected, sort the elements of the array using Bubble sort: //if option 2 is selected, sort the elements of the array using Insertion sort: //if option 3 is selected, sort the elements of the array using Selection sort: BubbleSort.java import java.util.*; class BubbleSort{ 1 InsertionSort.java // Driver method to test above public static void main(String args[]) { I/declare an array of integers int intarray[] {23,43,13,65,11,62,76,83,9,71,84,34,96,80}; I/print original array System.out.println("Original array: " + Arrays.toString(intArray)); int n = intArray.length; //iterate over the array comparing adjacent elements for (int i = e; i < n-1; i++) for (int j = 0; j =0 && temp <= numArray[j]) 4 3 6 4 5 8. 6 9 10 { 11 9 12 10 //if elements not in order, swap them if (intArray[j] > intArray[j+1]) { int temp - intArray[j]; intArray[j] - intArray[j+1]; intArray[j+1] - temp; 13 11 { 14 12 numArray[j+1] = numArray[j]; 15 13 j- j-1; 16 14 17 15 numArray[j+1] - temp; 18 } 16 //print the sorted array System.out.println("Sorted array: } 19 I/print the sorted array System.out.println("Sorted Array:" + Arrays.tostring(numArray)): } } 17 20 + Arrays.toString(intArray)); 18 21 19 22 20 SelectionSort.java 1 import java.util.*; class SelectionSort { static void sel_sort(int numArray[]) 3 4 5 6 int n = numArray.length; // traverse unsorted array for (int i = e; i < n-1; i++) { // Find the minimum element in unsorted array 8 9 10 11 int min_idx i; for (int j = i+1; j < n; j++) if (numArray[j] < numArray[min_idx]) min_idx = j; 12 13 14 15 16 // swap minimum element with compared element int temp = numArray[min_idx]; numArray[min_idx] = numArray[i]; numArray[i] = temp; 17 18 19 20 21 22 } 23 public static void main(String args[]) { //declare and print the original array 24 25 26 int numArray[] {8,4,1,15,52,12,32,11,23}; System.out.println("Original Array:" + Arrays.tostring(numArray)) 27 28 29 //call selection sort routine sel_sort(numArray); I/print the sorted array System.out.printin("Sorted Array:" + Arrays.tostring(numArray)); 30 31 32 33 34 }
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![GENERAL ENGINEERING
Perform the following data structure on Sorting:
BASIC PROGRAMMING
CREATE an array with at least 5 in size and put elements in the array. Perform the
following:
Sorting Data Structure operation:
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
CHOOSE OPE RATION:
// if option 1 is selected, sort the elements of the array using Bubble sort:
//if option 2 is selected, sort the elements of the array using Insertion sort:
//if option 3 is selected, sort the elements of the array using Selection sort:
BubbleSort.java
import java.util.*;
class BubbleSort{
1
2
InsertionSort.java
// Driver method to test above
public static void main(String args[]) {
//declare an array of integers
int intArray[] = {23,43,13,65,11,62,76,83,9,71,84,34,96,8e};
//print original array
System.out.println("Original array:
int n - intArray.length;
3
import java.util.*;
public class InsertionSort {
public static void main(String[] args) {
//declare an array and print the original contents
int[] numArray = {10,6,15,4,1,45};
System.out.println("Original Array:" + Arrays.toString(numArray)
1
4
2
5
6
7
5
+ Arrays.toString(intArray));
6
9
//apply insertion sort algorithm on the array
for(int k=1; k<numArray.length-1; k++)
int temp = numArray[k];
int j- k-1;
7
//iterate over the array comparing adjacent elements
for (int i = 0; i < n-1; i++)
for (int j = e; j <n-i-1; j++)
10
8
{
11
9
12
10
//if elements not in order, swap them
if (intArray[j] > intArray[j+1]) {
int temp - intArray[j];
intArray[j] = intArray[j+1];
intarray[j+1] - temp;
13
while(j>=0 && temp <= numArray[j])
numArray[j+1] - numArray[j];
j = j-1;
11
{
14
12
15
13
16
14
numArray[j+1] = temp;
}
//print the sorted array
System.out.println("Sorted Aray:" + Arrays.tostring(numArray));
17
15
18
16
19
//print the sorted array
17
+ Arrays.toString(intArray));
System.out.println("Sorted aray:
}
}
20
18
21
19
22
20
}
SelectionSort.java
1
import java.util.*;
2.
class SelectionSort
{
static void sel_sort(int numArray[])
{
int n = numArray.length;
4
// traverse unsorted array
for (int i = 0; i < n-1; i++)
8
{
// Find the minimum element in unsorted array
int min_idx - i;
for (int j = i+1; j < n; j++)
if (numArray[j] < numArray[min_idx])
10
11
12
13
14
15
min_idx = j;
16
// swap minimum element with compared element
int temp = numArray[min_idx];
numArray[min_idx] = numArray[i];
numArray[i] = temp;
17
18
19
20
21
22
}
23
24
public static void main(String args[])
25
//declare and print the original array
int numArray[] = {8,4,1,15,52,12,32,11,23};
System.out.println("Original Array:" + Arrays.toString(numArray))
26
27
28
29
//call selection sort routine
sel_sort(numArray);
//print the sorted array
System.out.println("Sorted Array:" + Arrays.tostring(numArray));
}
30
31
32
33
34
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc3a8efc8-550e-40f4-9b5a-b597e7f065c1%2F5ae51c96-162a-445c-a4e1-20fa2a9537b9%2F90qsl9t_processed.jpeg&w=3840&q=75)
Transcribed Image Text:GENERAL ENGINEERING
Perform the following data structure on Sorting:
BASIC PROGRAMMING
CREATE an array with at least 5 in size and put elements in the array. Perform the
following:
Sorting Data Structure operation:
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
CHOOSE OPE RATION:
// if option 1 is selected, sort the elements of the array using Bubble sort:
//if option 2 is selected, sort the elements of the array using Insertion sort:
//if option 3 is selected, sort the elements of the array using Selection sort:
BubbleSort.java
import java.util.*;
class BubbleSort{
1
2
InsertionSort.java
// Driver method to test above
public static void main(String args[]) {
//declare an array of integers
int intArray[] = {23,43,13,65,11,62,76,83,9,71,84,34,96,8e};
//print original array
System.out.println("Original array:
int n - intArray.length;
3
import java.util.*;
public class InsertionSort {
public static void main(String[] args) {
//declare an array and print the original contents
int[] numArray = {10,6,15,4,1,45};
System.out.println("Original Array:" + Arrays.toString(numArray)
1
4
2
5
6
7
5
+ Arrays.toString(intArray));
6
9
//apply insertion sort algorithm on the array
for(int k=1; k<numArray.length-1; k++)
int temp = numArray[k];
int j- k-1;
7
//iterate over the array comparing adjacent elements
for (int i = 0; i < n-1; i++)
for (int j = e; j <n-i-1; j++)
10
8
{
11
9
12
10
//if elements not in order, swap them
if (intArray[j] > intArray[j+1]) {
int temp - intArray[j];
intArray[j] = intArray[j+1];
intarray[j+1] - temp;
13
while(j>=0 && temp <= numArray[j])
numArray[j+1] - numArray[j];
j = j-1;
11
{
14
12
15
13
16
14
numArray[j+1] = temp;
}
//print the sorted array
System.out.println("Sorted Aray:" + Arrays.tostring(numArray));
17
15
18
16
19
//print the sorted array
17
+ Arrays.toString(intArray));
System.out.println("Sorted aray:
}
}
20
18
21
19
22
20
}
SelectionSort.java
1
import java.util.*;
2.
class SelectionSort
{
static void sel_sort(int numArray[])
{
int n = numArray.length;
4
// traverse unsorted array
for (int i = 0; i < n-1; i++)
8
{
// Find the minimum element in unsorted array
int min_idx - i;
for (int j = i+1; j < n; j++)
if (numArray[j] < numArray[min_idx])
10
11
12
13
14
15
min_idx = j;
16
// swap minimum element with compared element
int temp = numArray[min_idx];
numArray[min_idx] = numArray[i];
numArray[i] = temp;
17
18
19
20
21
22
}
23
24
public static void main(String args[])
25
//declare and print the original array
int numArray[] = {8,4,1,15,52,12,32,11,23};
System.out.println("Original Array:" + Arrays.toString(numArray))
26
27
28
29
//call selection sort routine
sel_sort(numArray);
//print the sorted array
System.out.println("Sorted Array:" + Arrays.tostring(numArray));
}
30
31
32
33
34
}
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY