1
1
package com .thealgorithms .datastructures .lists ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .List ;
4
5
5
6
/**
6
7
* A SortedLinkedList is a data structure that maintains a sorted list of elements.
7
8
* Elements are ordered based on their natural ordering or by a Comparator provided at the time of creation.
8
9
* This implementation uses a singly linked list to store the elements.
9
10
* Further details can be found on this link
10
11
* 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
13
12
*/
14
-
15
13
public class SortedLinkedList {
16
14
private Node head ;
17
15
private Node tail ;
@@ -111,31 +109,14 @@ public boolean search(int value) {
111
109
public boolean isEmpty () {
112
110
return head == null ;
113
111
}
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
-
131
112
/**
132
113
* Returns a string representation of the sorted linked list.
133
114
* @return a string representation of the sorted linked list
134
115
*/
135
116
@ Override
136
117
public String toString () {
137
118
if (this .head != null ) {
138
- ArrayList <String > elements = new ArrayList <>();
119
+ List <String > elements = new ArrayList <>();
139
120
Node temp = this .head ;
140
121
while (temp != null ) {
141
122
elements .add (String .valueOf (temp .value ));
@@ -147,8 +128,8 @@ public String toString() {
147
128
}
148
129
}
149
130
150
- public class Node {
151
- public int value ;
131
+ public final class Node {
132
+ public final int value ;
152
133
public Node next ;
153
134
154
135
public Node () {
0 commit comments