Skip to content

Commit 16cdb60

Browse files
committed
Addressed comments by alxkm
1 parent 5693923 commit 16cdb60

File tree

2 files changed

+4
-42
lines changed

2 files changed

+4
-42
lines changed

src/main/java/com/thealgorithms/datastructures/lists/SortedLinkedList.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package com.thealgorithms.datastructures.lists;
22

33
import java.util.ArrayList;
4+
import java.util.List;
45

56
/**
67
* A SortedLinkedList is a data structure that maintains a sorted list of elements.
78
* Elements are ordered based on their natural ordering or by a Comparator provided at the time of creation.
89
* This implementation uses a singly linked list to store the elements.
910
* Further details can be found on this link
1011
* https://runestone.academy/ns/books/published/cppds/LinearLinked/ImplementinganOrderedList.html
11-
* @author Muhammad Junaid Khalid
12-
* @param int the type of elements in this list
1312
*/
14-
1513
public class SortedLinkedList {
1614
private Node head;
1715
private Node tail;
@@ -111,31 +109,14 @@ public boolean search(int value) {
111109
public boolean isEmpty() {
112110
return head == null;
113111
}
114-
115-
/**
116-
* Returns the minimum value in the sorted linked list.
117-
* @return the minimum value
118-
*/
119-
public int minValue() {
120-
return this.head.value;
121-
}
122-
123-
/**
124-
* Returns the maximum value in the sorted linked list.
125-
* @return the maximum value
126-
*/
127-
public int maxValue() {
128-
return this.tail.value;
129-
}
130-
131112
/**
132113
* Returns a string representation of the sorted linked list.
133114
* @return a string representation of the sorted linked list
134115
*/
135116
@Override
136117
public String toString() {
137118
if (this.head != null) {
138-
ArrayList<String> elements = new ArrayList<>();
119+
List<String> elements = new ArrayList<>();
139120
Node temp = this.head;
140121
while (temp != null) {
141122
elements.add(String.valueOf(temp.value));
@@ -147,8 +128,8 @@ public String toString() {
147128
}
148129
}
149130

150-
public class Node {
151-
public int value;
131+
public final class Node {
132+
public final int value;
152133
public Node next;
153134

154135
public Node() {

src/test/java/com/thealgorithms/datastructures/lists/SortedLinkedListTest.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,6 @@ public void testSearch() {
3737
assertTrue(list.search(5));
3838
assertFalse(list.search(10));
3939
}
40-
41-
@Test
42-
public void testMinValue() {
43-
SortedLinkedList list = new SortedLinkedList();
44-
list.insert(5);
45-
list.insert(3);
46-
list.insert(7);
47-
assertEquals(3, list.minValue());
48-
}
49-
50-
@Test
51-
public void testMaxValue() {
52-
SortedLinkedList list = new SortedLinkedList();
53-
list.insert(5);
54-
list.insert(3);
55-
list.insert(7);
56-
assertEquals(7, list.maxValue());
57-
}
58-
5940
@Test
6041
public void testEmptyList() {
6142
SortedLinkedList list = new SortedLinkedList();

0 commit comments

Comments
 (0)