Implement a modification of the SelectionSorter class that reorders the array to have even elements followed by odd ones. Follow the basic steps of the selection sort algorithm. Locate the next even element and swap it with the current one. The algorithm places the even elements first, maintaining their original order. The odd elements may be in a different order. For example, SelectionSorter.java 1 import java.util.Arrays; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 [2,5,6,3,4,6,9,1,2] [2,6,5,3,4,6,9,1,2] [2,6,4,3,5,6,9,1,2] [2,6,4,6,5,3,9,1,2] [2,6,4,6,2,3,9,1,5] 53 54 55 56 57 58 59 60 /** This modified SelectionSorter class places the even elements followed by the odd elements in the array, maintaining the original order of the even elements. */ public class SelectionSorter { 61 62 63 64 } private int[] a; /** */ public SelectionSorter(int[] anArray) { } /** Constructs a selection sorter. @param anArray the array to sort a = anArray; Places the even elements followed by the odd elemens in the array, maintaining the ori order of the even elements. Visit each element of the array, swapping odd elements with the first even one that follows. For example: [5,6,4,6,9,2] [6,5,4,6,9,2] [6,4,5,6,9,2] [6,4,6,5,9,2] [6,4,6,2,9,5] */ public void evenOdd () { } /** Finds the first even element starting at posiion index. @return the position first even element } // TODO */ private int firstEven (int index). { // TODO } /** Swaps two entries of the array. @param i the first position to swap @param j the second position to swap */ private void swap (int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } // this method is used to check your work public static int[] check(int[] values) { SelectionSorter sorter = new SelectionSorter(values); sorter.evenOdd (); return values;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

JAVA

Implement a modification of the SelectionSorter class that reorders the array to have even elements followed by odd ones. Follow the basic steps of
the selection sort algorithm. Locate the next even element and swap it with the current one. The algorithm places the even elements first,
maintaining their original order. The odd elements may be in a different order. For example,
[2,5,6,3,4,6,9,1,2]
[2,6,5,3,4,6,
6,9,1,2]
[2,6,4,3,5,6,9,1,2]
[2,6,4,6,5, 3,9,1,2]
[2,6,4,6,2,3,9,1,5]
SelectionSorter.java
1 import java.util.Arrays;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
This modified SelectionSorter class places the even elements followed by the odd
elements in the array, maintaining the original order of even elements.
*/
public class SelectionSorter
{
63
64 }
private int[] a;
/**
*/
public SelectionSorter(int[] anArray)
{
}
/**
Constructs a selection sorter.
@param anArray the array to sort
a = anArray;
Places the even elements followed by the odd elemens in the array, maintaining the ori
order of the even elements. Visit each element of the array, swapping odd
elements with the first even one that follows. For example:
[5,6,4,6,9,2]
[6,5,4,6,9,2]
[6,4,5,6,9,2]
[6,4,6,5,9,2]
[6,4,6,2,9,5]
*/
public void evenOdd ()
{
// TODO
}
}
Finds the first even element starting at posiion index
@return the position first even element
*/
private int firstEven (int index)
{
}
/**
// TODO
Swaps two entries of the array.
@param i the first position to swap
@param j the second position to swap
*/
private void swap (int i, int j)
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
// this method is used to check your work
public static int[] check(int[] values)
{
SelectionSorter sorter = new SelectionSorter (values);
sorter.evenOdd ();
return values;
Transcribed Image Text:Implement a modification of the SelectionSorter class that reorders the array to have even elements followed by odd ones. Follow the basic steps of the selection sort algorithm. Locate the next even element and swap it with the current one. The algorithm places the even elements first, maintaining their original order. The odd elements may be in a different order. For example, [2,5,6,3,4,6,9,1,2] [2,6,5,3,4,6, 6,9,1,2] [2,6,4,3,5,6,9,1,2] [2,6,4,6,5, 3,9,1,2] [2,6,4,6,2,3,9,1,5] SelectionSorter.java 1 import java.util.Arrays; 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 /** This modified SelectionSorter class places the even elements followed by the odd elements in the array, maintaining the original order of even elements. */ public class SelectionSorter { 63 64 } private int[] a; /** */ public SelectionSorter(int[] anArray) { } /** Constructs a selection sorter. @param anArray the array to sort a = anArray; Places the even elements followed by the odd elemens in the array, maintaining the ori order of the even elements. Visit each element of the array, swapping odd elements with the first even one that follows. For example: [5,6,4,6,9,2] [6,5,4,6,9,2] [6,4,5,6,9,2] [6,4,6,5,9,2] [6,4,6,2,9,5] */ public void evenOdd () { // TODO } } Finds the first even element starting at posiion index @return the position first even element */ private int firstEven (int index) { } /** // TODO Swaps two entries of the array. @param i the first position to swap @param j the second position to swap */ private void swap (int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } // this method is used to check your work public static int[] check(int[] values) { SelectionSorter sorter = new SelectionSorter (values); sorter.evenOdd (); return values;
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Array
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education