JavaAlgorithms
Elementary and no so elementary Java algorithms
listAlgorithms.Algorithms Class Reference

List of all members.

Static Public Member Functions

static< TextendsComparable< T >
ListNode< T > 
buildList (T[] vals)
static< TextendsComparable< T >
boolean 
listEquals (ListNode< T > listA, ListNode< T > listB)
static< TextendsComparable< T >
ListNode< T > 
reverse (ListNode< T > head)
static< TextendsComparable< T >
void 
dedup (ListNode< T > head)
static< TextendsComparable< T >
ListNode< T > 
kthFromEnd (ListNode< T > head, int k)

Detailed Description

Algorithms

A small collection of list algorithms

Jun 19, 2013

Author:
Ian Kaplan, iank@bearcave.com

Definition at line 23 of file Algorithms.java.


Member Function Documentation

static <TextendsComparable<T> ListNode<T> listAlgorithms.Algorithms.buildList ( T[]  vals) [static]

Build a list from an array of values

Parameters:
valsan array of values
Returns:
the list construdted from values

Definition at line 35 of file Algorithms.java.

static <TextendsComparable<T> void listAlgorithms.Algorithms.dedup ( ListNode< T >  head) [static]

Remove duplicate elements from a list. The input list is modified.

Parameters:
head

Definition at line 117 of file Algorithms.java.

static <TextendsComparable<T> ListNode<T> listAlgorithms.Algorithms.kthFromEnd ( ListNode< T >  head,
int  k 
) [static]

Return the kth element from the end of the list

Parameters:
headthe start of the list
kthe value of k
Returns:
the kth node from the end of the list, or if the list length is less than k, null

Definition at line 144 of file Algorithms.java.

static <TextendsComparable<T> boolean listAlgorithms.Algorithms.listEquals ( ListNode< T >  listA,
ListNode< T >  listB 
) [static]

Compare two lists

Parameters:
listA
listB
Returns:
true if the lists are equal (and have equal length), false otherwise.

Definition at line 59 of file Algorithms.java.

static <TextendsComparable<T> ListNode<T> listAlgorithms.Algorithms.reverse ( ListNode< T >  head) [static]

Reverse the element in a list

                               A -> B -> C -> D
     A -> null                 B -> C -> D -> null
     B -> A -> null            C -> D -> null
     C -> B -> A -> null       D -> null
     D -> C-> B -> A -> null
 

The input list is reversed, so its original structure is destroyed

Parameters:
headthe start of a list
Returns:
the head of the reversed list

Definition at line 96 of file Algorithms.java.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables