Object - streams : LinkedList

The LinkedList object which represents the linked list data structure.

Methods

isEmpty

Checks if the linked list is empty.

resetToFront

Moves the cursoer to the front/head of the linked list.

resetToRear

Moves the cursor to the end of the linked list if the cursor is not already at the last element of the linked list.

hasNext

Returns true if the linked list has more elements starting from the current cursor location.

hasPrevious

Returns true if there are prior elements to the current element/cursor location, otherwise false.

next

Returns the next element of the linked list and moves the cursor to the next element.

previous

Returns the previous element of the linked list and moves the cursor to the previous element.

removeCurrent

Removes the element at the current cursor location.

getSize

Returns the current number of elements in the linked list.

clear

Empties the linked list.

removeFirstOccurrence

Removes the first occurence of the element pass as elem and return true of the removal is successful.

remove

Removes the first occurence of the element pass as elem and return true of the removal is successful.

getFirst

Returns the first element of the linked list, without moving the cursor.

getLast

Returns the last element of the linked list, without moving the cursor.

addFirst

Adds a new element to the front of the linked list without moving the cursor.

addLast

Adds a new element to the end of the linked list without moving the cursor.

removeFirst

Removes the first element in the linked list without moving the cursor.

removeLast

Removes the last element in the linked list without moving the cursor.

insertBeforeCurrent

Insert a new element before the current cursor location.

dequeue

Returns the first element which is added to the linked list.

asArray

Creates an array from the elements in the linked list and return it. The cursor will not be changed.

addAll

Adds elements of an array to the current cursor location and moves the cursor to the end of the list.

Fields

  • first Node?
  • description

  • last Node?
  • description

  • curr Node?
  • description

  • size int 0
  • description

isEmpty

()

returns boolean

Checks if the linked list is empty.

  • Return Type

    (boolean)
  • Returns true if the linked list is empty, otherwise returns false.

resetToFront

Moves the cursoer to the front/head of the linked list.

resetToRear

Moves the cursor to the end of the linked list if the cursor is not already at the last element of the linked list.

hasNext

()

returns boolean

Returns true if the linked list has more elements starting from the current cursor location.

  • Return Type

    (boolean)
  • Returns true if there are more elements onwards from the current cursor location, otherwise false.

hasPrevious

()

returns boolean

Returns true if there are prior elements to the current element/cursor location, otherwise false.

  • Return Type

    (boolean)
  • Returns true, if there are elements prior to the current cursor location, otherwise false.

Returns the next element of the linked list and moves the cursor to the next element.

  • Return Type

    (any?)
  • The next element from the current cursor location.

Returns the previous element of the linked list and moves the cursor to the previous element.

  • Return Type

    (any?)
  • The previous element from the current cursor location.

removeCurrent

Removes the element at the current cursor location.

getSize

()

returns int

Returns the current number of elements in the linked list.

  • Return Type

    (int)
  • The number of elements in the linked list.

clear

Empties the linked list.

removeFirstOccurrence

(any? elem)

returns boolean

Removes the first occurence of the element pass as elem and return true of the removal is successful.

Parameters

  • Return Type

    (boolean)
  • Return true if removal is successful otherwise false.

remove

(any? elem)

returns boolean

Removes the first occurence of the element pass as elem and return true of the removal is successful.

Parameters

  • Return Type

    (boolean)
  • Return true if removal is successful otherwise false.

getFirst

()

returns any?

Returns the first element of the linked list, without moving the cursor.

  • Return Type

    (any?)
  • First element of the linked list.

getLast

()

returns any?

Returns the last element of the linked list, without moving the cursor.

  • Return Type

    (any?)
  • Last element of the linked list.

addFirst

Adds a new element to the front of the linked list without moving the cursor.

Parameters

  • data any
  • Data to be added to the front of the linked list.

addLast

Adds a new element to the end of the linked list without moving the cursor.

Parameters

  • data any
  • Data to be added to the end of the linked list.

removeFirst

()

returns any?

Removes the first element in the linked list without moving the cursor.

  • Return Type

    (any?)
  • Returns the removed element.

removeLast

()

returns any?

Removes the last element in the linked list without moving the cursor.

  • Return Type

    (any?)
  • Returns the removed element.

insertBeforeCurrent

Insert a new element before the current cursor location.

Parameters

  • data any
  • Data to be inserted.

dequeue

()

returns any?

Returns the first element which is added to the linked list.

  • Return Type

    (any?)
  • The dequeued element.

asArray

()

returns any[]

Creates an array from the elements in the linked list and return it. The cursor will not be changed.

  • Return Type

    (any[])
  • An array of elements in the linked list.

addAll

Adds elements of an array to the current cursor location and moves the cursor to the end of the list.

Parameters

  • data any[]
  • The array to be added to the linked list.