Package MediaPlayer

Class 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.
    • Constructor Detail

      • BetterLinkedList

        public BetterLinkedList()
    • 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 swapped
        j - 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