SingleLinkedList

Kind of class:class
Inherits from:none
Classpath:org.springsoft.aslib.SingleLinkedList
File last modified:Saturday, 22 January 2005, 14:27:02

Summary


Constructor
Instance properties
Instance methods

Constructor

SingleLinkedList

function SingleLinkedList (
)

SingleLinkedList Constructor

Instance properties

head_

private head_:ListNode
(read)

Instance methods

get

function get (
key:Number) : ListNode

Get a node reference
Parameters:
key:
The numeric key for finding node
Returns:
  • ListNode if we find the key. Otherwise returns null.

getAt

function getAt (
index:Number) : ListNode

Get a node at index
Parameters:
index:
The numeric index to locate node
Returns:
  • ListNode if we locate the index. Otherwise returns null.

getData

function getData (

Get a SingleLinkedListObject data object reference
Parameters:
key:
The numeric key to find SingleLinkedListObject
Returns:
  • SingleLinkedListObject if we find the key. Otherwise returns null.

getDataAt

function getDataAt (
index:Number) : SingleLinkedListObject

Get a SingleLinkedListObject data object reference
Parameters:
index:
The numeric index to locate SingleLinkedListObject
Returns:
  • SingleLinkedListObject if we locate the index. Otherwise returns null.

getFront

function getFront (
canDelete:Boolean) : ListNode

Return the front node and delete front node if canDelete is set to true
Parameters:
canDelete:
Flag that indicates if we can delete the front node
Returns:
  • ListNode if list is not empty. Otherwise returns null.

getFrontData

function getFrontData (
canDelete:Boolean) : SingleLinkedListObject

Return the front SingleLinkedListObject and delete front SingleLinkedListObject if canDelete is set to true
Parameters:
canDelete:
Flag that indicates if we can delete the front SingleLinkedListObject
Returns:
  • SingleLinkedListObject if list is not empty. Otherwise returns null.

hasOneNode

private function hasOneNode (
Void) : Boolean

Test if list has only one node
Returns:
  • true if list has only one node. Otherwise returns false.

insert

function insert (

Insert a SingleLinkedListObject. By default we insert at front of list
Parameters:
data:
The SingleLinkedListObject's data object

insertEnd

private function insertEnd (
node:ListNode, targetNode:ListNode) : Void

Insert at end
Parameters:
node :
Node that needs to be inserted
targetNode:
Insert node after targetNode

insertFront

private function insertFront (
node:ListNode) : Void

Insert at front
Parameters:
node:
Insert node at front of list

insertMiddle

private function insertMiddle (
node:ListNode, targetNode:ListNode) : Void

Insert at middle
Parameters:
node :
Node that needs to be inserted
targetNode:
Insert node after targetNode

insertTail

function insertTail (

Insert a SingleLinkedListObject at tail
Parameters:
data:
The SingleLinkedListObject's data object

isEmpty

function isEmpty (
Void) : Boolean

Test for empty list
Returns:
  • true if the linked list is empty. Otherwise returns false.

isEnd

private function isEnd (
node:ListNode) : Boolean

Test for end node
Parameters:
node:
Test for end node
Returns:
  • true if node is end node. Otherwise returns false.

isFront

private function isFront (
node:ListNode) : Boolean

Test for front node
Parameters:
node:
Test for front node
Returns:
  • true if node is front node. Otherwise returns false.

print

function print (
Void) : Void

Print linked list

remove

function remove (
key:Number) : ListNode

Remove a node
Parameters:
key:
The numeric key to find and remove node
Returns:
  • ListNode if list is not empty. Otherwise returns null.

removeAll

function removeAll (
) : Void

Remove all nodes

removeAt

function removeAt (
index:Number) : ListNode

Remove a node at index
Parameters:
index:
The numeric index to locate and remove node
Returns:
  • ListNode if list is not empty. Otherwise returns null.

removeData

function removeData (

Remove a SingleLinkedListObject
Parameters:
key:
The numeric key to find and remove SingleLinkedListObject
Returns:
  • SingleLinkedListObject if list is not empty. Otherwise returns null.

removeDataAt

function removeDataAt (
index:Number) : SingleLinkedListObject

Remove a SingleLinkedListObject at index
Parameters:
index:
The numeric index to locate and remove SingleLinkedListObject
Returns:
  • SingleLinkedListObject if list is not empty. Otherwise returns null.

removeEnd

private function removeEnd (
previous:ListNode) : ListNode

Remove from end
Parameters:
previous:
Node before node that needs to be removed
Returns:
  • ListNode

removeFront

private function removeFront (

Remove node from front of list
Returns:
  • ListNode if list is not empty. Otherwise returns false.

removeMiddle

private function removeMiddle (
previous:ListNode) : ListNode

Remove from middle
Parameters:
previous:
Node before node that needs to be removed
Returns:
  • ListNode

size

function size (
Void) : Number

Gets the size of the list
Returns:
  • the number of nodes in the list