class Linkedlist::Singly(T)

Defined in:

linkedlist/singly.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Intializes a singly linked list


[View source]

Instance Method Detail

def find_element(element : SinglyNode(T)) : SinglyNode(T) #

Returns the element if found or raises exception

Running time: O(n)


[View source]
def find_element(value : T) : SinglyNode(T) #

Returns the first element with value or raises exception if not found

Running time: O(n)


[View source]
def find_element?(element : SinglyNode(T)) : SinglyNode(T) | Nil #

Returns the element if found or nil if not found

Running time: O(n)


[View source]
def find_element?(value : T) : SinglyNode(T) | Nil #

Returns the first element with value or nil if not found

Running time: O(n)


[View source]
def head #

Returns the head of linked list

Running time: O(1)


[View source]
def insert_after(element : SinglyNode(T), mark : SinglyNode(T)) #

Inserts given element after the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_after(value : T, mark : SinglyNode(T)) : SinglyNode(T) #

Inserts new element after the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_after?(value : T, mark : SinglyNode(T)) : SinglyNode(T) | Nil #

Inserts new element after the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_before(element : SinglyNode(T), mark : SinglyNode(T)) #

Inserts given element before the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_before(value : T, mark : SinglyNode(T)) : SinglyNode(T) #

Inserts new element before the mark or raises exception if mark not found

Running time: O(n)


[View source]
def insert_before?(value : T, mark : SinglyNode(T)) : SinglyNode(T) | Nil #

Inserts new element before the mark or returns nil if mark not found

Running time: O(n)


[View source]
def insert_head(data : T) #

Inserts new element at the head of the linked list

Running time: O(1)


[View source]
def insert_tail(data : T) #

Inserts new element at the tail of the linked list

Running time: O(1)


[View source]
def length #

Returns the length of linked list.

Running time: O(1)


[View source]
def move_after(element : SinglyNode(T), mark : SinglyNode(T)) #

Moves element after the mark, if element and mark are present and not equal

Running time: O(n)


[View source]
def move_before(element : SinglyNode(T), mark : SinglyNode(T)) #

Moves element before the mark, if element and mark are present and not equal

Running time: O(n)


[View source]
def move_to_back(element : SinglyNode(T)) #

Moves element to front if found. List is unmodified otherwise.

Running time: O(n)


[View source]
def move_to_front(element : SinglyNode(T)) #

Moves element to front if found. List is unmodified otherwise.

Running time: O(n)


[View source]
def previous_element?(element : SinglyNode(T)) : SinglyNode(T) | Nil #

Returns the previous element if element found or nil if not found

Running time: O(n)


[View source]
def remove(element : SinglyNode(T)) : T #

Removes an element from the linked list and returns the data

Running time: O(n)


[View source]
def remove?(element : SinglyNode(T)) : SinglyNode(T) | Nil #

Removes an element from the linked list and returns the element

Running time: O(n)


[View source]
def tail #

Returns the tail of linked list

Running time: O(1)


[View source]