package com company class Node public int value public Node next publi

 1
 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
package com.company;
class Node {
public int value;
public Node next;
public Node(int givenval) {
value = givenval;
}
}
class List {
private int length;
private Node head;
private Node tail;
public List(Integer[] integers){
}
//adds a new node to the list with specified value
public void addtoList(int value) {
Node node = new Node(value);
if (length == 0) {
node.next = null;
} else {
node.next = head;
}
head = node;
length++;
}
//prints contents of the list
public void Print() {
Node node = head;
while (node != null) {
System.out.println(node.value);
node = node.next;
}
}
public void selectionSort(){
for(Node node1 = head; node1!=null; node1 = node1.next){//number of
//iterations
Node min = node1;//assumes min node is the node under considerations
//selects the min node
for(Node node2 = node1; node2!=null; node2 = node2.next){
if(min.value > node2.value){
min = node2;
}
}
//swaps the min node with the node in its actual position
Node temp = new Node(node1.value);
node1.value = min.value;
min.value =temp.value;}}}