Package MediaPlayer
Class BetterLinkedList<E>
- java.lang.Object
-
- MediaPlayer.LinkedList<E>
-
- MediaPlayer.BetterLinkedList<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>
public class BetterLinkedList<E> extends LinkedList<E>
BetterLinkedList class Extends (my custom) LinkedList class Adds the ability to elements and sort them.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class MediaPlayer.LinkedList
LinkedList.Node
-
-
Field Summary
-
Fields inherited from class MediaPlayer.LinkedList
head, size
-
-
Constructor Summary
Constructors Constructor Description BetterLinkedList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
sort()
Sorts the elements in this list in ascending order.void
swap(int i, int j)
Swaps the elements at the specified positions in this list.void
swapWithNext(int i)
Swaps the element at the specified position with the next element in this list.-
Methods inherited from class MediaPlayer.LinkedList
add, addFirst, addLast, clear, contains, get, getFirst, getLast, indexOf, isEmpty, iterator, remove, removeFirst, removeLast, reverse, size, toString
-
-
-
-
Method Detail
-
swap
public void swap(int i, int j)
Swaps the elements at the specified positions in this list.- Parameters:
i
- the index of the first element to be swappedj
- the index of the second element to be swapped- Throws:
java.lang.IndexOutOfBoundsException
- if either index is out of range (i < 0 || i >= size || j < 0 || j >= size)
-
swapWithNext
public void swapWithNext(int i)
Swaps the element at the specified position with the next element in this list. Is more efficient than swap(i,i+1) because it avoids two linear searches.- Parameters:
i
- the index of the element to be swapped with its next element- Throws:
java.lang.IndexOutOfBoundsException
- if the index is out of range (i < 0 || i >= size - 1)
-
sort
public void sort()
Sorts the elements in this list in ascending order. This method uses a simple bubble sort algorithm to arrange the elements. The elements must implement the Comparable interface for the sorting to work correctly.- Throws:
java.lang.ClassCastException
- if the list contains elements that do not implement Comparable
-
-