Java Reference
In-Depth Information
}
prev = next;
}
return count;
}
5. public static void insertInOrder(LinkedList<String> list,
String value) {
int index = 0;
Iterator<String> i = list.iterator();
String next = i.next();
// advance until the proper index
while (i.hasNext() && next.compareTo(value) < 0) {
next = i.next();
index++;
}
list.add(index, value);
}
6. public static void removeAll(LinkedList<Integer> list,
int value) {
Iterator<Integer> i = list.iterator();
while (i.hasNext()) {
if (i.next() == value) {
i.remove();
}
}
}
7. public static void wrapHalf(LinkedList<Integer> list) {
int halfSize = (list.size() + 1) / 2;
for (int i = 0; i < halfSize; i++) {
// wrap around one element
int element = list.remove(list.size() - 1);
list.add(0, element);
}
}
8. An abstract data type defines the type of data that a collection can hold and the
operations that it can perform on that data. Linked lists implement the List
abstract data type.
Search WWH ::




Custom Search