Package dsa

Class LinearSearchST<K,V>

java.lang.Object
dsa.LinearSearchST<K,V>
Type Parameters:
K - the type of keys in the symbol table.
V - the type of values in the symbol table.
All Implemented Interfaces:
BasicST<K,V>

public class LinearSearchST<K,V> extends Object implements BasicST<K,V>
This data type provides an implementation of the basic symbol table (BasicST) API, using a linked-list as the underlying data structure.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty symbol table.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(K key)
    Returns true if this symbol table contains key, and false otherwise.
    void
    delete(K key)
    Deletes key and the associated value from this symbol table.
    get(K key)
    Returns the value associated with key in this symbol table, or null.
    boolean
    Returns true if this symbol table is empty, and false otherwise.
    Returns all the keys in this symbol table.
    static void
    main(String[] args)
    Unit tests the data type.
    void
    put(K key, V value)
    Inserts the key and value pair into this symbol table.
    int
    Returns the number of key-value pairs in this symbol table.
    Returns a string representation of this symbol table.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LinearSearchST

      public LinearSearchST()
      Constructs an empty symbol table.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns true if this symbol table is empty, and false otherwise.
      Specified by:
      isEmpty in interface BasicST<K,V>
      Returns:
      true if this symbol table is empty, and false otherwise.
    • size

      public int size()
      Returns the number of key-value pairs in this symbol table.
      Specified by:
      size in interface BasicST<K,V>
      Returns:
      the number of key-value pairs in this symbol table.
    • put

      public void put(K key, V value)
      Inserts the key and value pair into this symbol table.
      Specified by:
      put in interface BasicST<K,V>
      Parameters:
      key - the key.
      value - the value.
    • get

      public V get(K key)
      Returns the value associated with key in this symbol table, or null.
      Specified by:
      get in interface BasicST<K,V>
      Parameters:
      key - the key.
      Returns:
      the value associated with key in this symbol table, or null.
    • contains

      public boolean contains(K key)
      Returns true if this symbol table contains key, and false otherwise.
      Specified by:
      contains in interface BasicST<K,V>
      Parameters:
      key - the key.
      Returns:
      true if this symbol table contains key, and false otherwise.
    • delete

      public void delete(K key)
      Deletes key and the associated value from this symbol table.
      Specified by:
      delete in interface BasicST<K,V>
      Parameters:
      key - the key.
    • keys

      public Iterable<K> keys()
      Returns all the keys in this symbol table.
      Specified by:
      keys in interface BasicST<K,V>
      Returns:
      all the keys in this symbol table.
    • toString

      public String toString()
      Returns a string representation of this symbol table.
      Specified by:
      toString in interface BasicST<K,V>
      Overrides:
      toString in class Object
      Returns:
      a string representation of this symbol table.
    • main

      public static void main(String[] args)
      Unit tests the data type.
      Parameters:
      args - the command-line arguments.