Tutorial: Linked List II


by
Ronald S. Holland
Total Application Works
RonHolland@sumtotalz.com






To visit my site

HOME Consulting Design Maintenance Project Testing Training Turnkey Java C++ SQL HTML JavaScript


To contact us

© 2002 - 2011 All Rights Reserved Total Application Works


  • If you like this tutorial, tell a friend about it (copy and paste the following URL or send this page to a friend.)
    <html>
    <title>Example of a link </title>
    <body>
    <table border>
    <a href="http://sumtotalz.com/TotalAppsWorks/Linkedlist/LL_Tutorial_2.html"> Tutorial: Linked List II </a>
    </table>
    </body>
    </html>
    Download the source
  1. Java Table of contents
  2. 2nd Java Cup
  3. Pie Chart I
  4. Pie/Bar Chart IB
  5. Pie/Bar Chart II
  6. Pie/Bar Chart III
  7. A Basic Calculator
  8. Linked Lists
  9. Linked List II
  10. Linked List III
  11. Linked List IV
  12. Hardware Store I
  13. Hardware Store II
  14. Hardware Store III
  15. Client/Server
  16. Client/Server II
  17. Client/Server III
  18. Client/Server IV
  19. Multithreaded Client/Server
  20. Multithreaded Client/Server II
  21. Multithreaded Client/Server III
  22. Basic Calculator II
  23. Basic Calculator III

Introduction

This tutorial assumes that you have already mastered the preceding tutorial on this topic:

  1. Linked List I
In this tutorial, we will continue to develop our Linked List class. As a review, we define a Linked List in the next section.

What is a Linked List?

What is a Linked List? It is a self-referential class that contains a reference member and that member contains the address to a class object of the same class type. When the object points only to the next object or is a null pointer, it is a singly-linked list. In real life, there are many instances where we use addresses. For example, we use addresses

  • To designate where we live.
  • To designate where mail is to be sent.
  • To designate our email address.
We make use of this knowledge when we use a telephone book, a distribution/mailing list, and/or the firing order of a combustion engine. In the case of a telephone book, the information is organized by sections and sub-sections. For example, all last names starting with an "A" are found in the major section pointing to an ordered list of last names that begin with "A".
  
+----+    +----+     +----+      +----+    +----+    +----+ 
| A  |    | B  |     | C  | ...  | X  |    | Y  |    | Z  |   <-- major nodes
+-+--+    +-+--+     +-+--+      +-+--+    +-+--+    +-+--+     
  |         |          |           |         |         |   
  |         V          V           V         V         |
  |                                                    |
  V                                                    V 
+-+---------+                                       +--+--------+   
| Last      |                                       | Last      |
| Names     |                                       | Names     | 
| Starting  |                                       | Starting  | 
| With      |                                       | With      | 
| "A"       |                                       | "Z"       |  
+-----------+                                       +-----------+
 
Figure 1: Telephone book using a linked list


A Linked List is like a chain where each link in the chain contains the address to the next link in the chain. A class of this type might look like:

  
class node {
   private int data;
   private next refA;

   public node() {}
   void setData( int ) {}
   int getData(  int ) {}
   void setNextRef( node ref ) {}
   node getNextRef( ) {} 
   void init(  ) {}
   void AppendNode( int ) {}
   void InsertNode( int ) {}
   void DeleteNode( int ) {}
   void DisplayList( int ) {}
}
Figure 2: A Linked List Class
After the above class is run and data is inserted into the linked list, the chain might look something like the following:

  
    HEAD
+-----------+
| reference | <-- contains the address to the start
+-----+-----+     of the linked list
      | 
      V   
+-----+-----+      +-----------+      +-----------+
|   data    |  +-->|   data    |  +-->|   data    |
+-----------+  |   +-----------+  |   +-----------+
| reference |--+   | reference |  |   | reference |
+-----------+      +-----+-----+  |   +-----+-----+
                         |        |
      +------------------+        |
      |                           |
      V                           |
+-----+-----+      +-----------+  |
|   data    |  +-->|   data    |  |
+-----------+  |   +-----------+  | 
| reference |--+   | reference |--+
+-----------+      +-----------+
Figure 3: chain of Nodes

In an array, data is stored in contiguous memory and can be accessed by using a reference and an index. For example,
  
int ar[] = new int[ 12] ;
 
for ( int i = 0 ; i < ar.length ; i++ )
   ar[ i ] = i ;
Figure 4: Declaring, allocating and filling an array


The above code segment loads the value of i in each succeeding location of the array named ar.

An array is different than a linked list in many ways. In an array,

  • The data is stored in contiguous physical memory.
  • The contiguous memory is addressed using a reference to the first location.
  • By using the name of the array and an index, the data is accessed. For example,
      
    ar[ 1 ] = 5 ;
    
  • The location of the array is resolved at compile time.

The organization of data in an array is physical. A linked list

  • Stores data based on the logical order of the data and not the physical order.
    • In other words, a linked list gives the appearance that the data in the list is stored in contiguous memory.
  • Instead of an index, all stored data records are assigned a physical address in memory that the link list algorithm/logic uses to locate the information.
  • A linked list logically organizes the data, rather than by physical address.
  • The memory for each node in the linked list is dynamically allocated at run time.

Requirements for a Linked List

This program is intended to be an introduction to linked lists. As such, the requirements are:

  1. Write this program as an application.
  2. The linked list node should be added to the linked list in a LIFO manner
    • All new nodes should be added at the head of the linked list
  3. Create an Add method to add new nodes to the linked list
  4. Create a Remove method to delete/remove nodes from the linked list
  5. Create an DisplayLL method to show the contents of the nodes
  6. New requirements for this tutorial
    1. Modify the add method so that elements are added in ascending sorted order.
    2. Create an addLast method to add new elements to the tail/end of the list.
    3. Create an addFirst method to add new elements to the head of the list.
    4. Create an Remove method to delete an element from the Linked List.
    5. Create an isEmpty method to determine if the Linked List has any entries.
    6. Create a contains method that finds out if a particular value is in the Linked List.
    7. Create a toArray method that retrieves the elements in the Linked List and stores them in an array.
    8. Create a getLast method that returns the last element in the Linked List.
    9. Create a size method that discovers the number of elements in the Linked List.
  7. Use Holland's OOP Programming Design Model to build this program

What is the Holland's OOP Programming Design Model?

In object-oriented programming, programming revolves around the data. So in this style, the top is the data. It might be depicted as follows:

Holland's OOP Programming Design Model
  
          +--------------+
          |      Data    |<----+  
          +-------+------+     | 
                  ^            |
                  |----------->+
                  V            ^
          +-------+------+     |
          |   Top-down   |     | 
          |  Structured  |<----+
          |  programming |     |
          |  on Classes  |     | (step-wise)
          |  and methods |     | (refinement)
          +--------------+     | (as needed or as the) 
                  |            | (application ages)
                  +------------+ 
 
  
Figure 5:


The integer data is entered via prompts (JOptionPane) from the application. This data is initially defined by requirement 1 above. As the application ages, the address data/record may change. Requirement 3 to 6 lists the initial methods to be built with this application. In the next section, I will describe how to build the Linked List template.

A Possible Approach to Building an Application

When we look at the requirements (clues), a few items jump out at us.

  1. application - a program with a main() method
  2. Create an Insert method
    • All new nodes should be added at the head of the linked list
      • This means that items will be added as though they were being pushed on a stack
  3. Create an DisplayLL method
  4. Modify the add method so that elements are added in ascending sorted order.
  5. Create an addLast method to add new elements to the tail/end of the list.
  6. Create an addFirst method to add new elements to the head of the list.
  7. Create an Remove method to delete an element from the Linked List.
  8. Create an isEmpty method to determine if the Linked List has any entries.
  9. Create a contains method that finds out if a particular value is in the Linked List.
  10. Create a toArray method that retrieves the elements in the Linked List and stores them in an array.
  11. Create a getLast method that returns the last element in the Linked List.
  12. Create a size method that discovers the number of elements in the Linked List.
    • Start at the head of the linked list and walk the list until all of the node data has been displayed

Over the years, I have seen various approaches to building an application. I will use the following simple top-down approach of using templates. In the first step of our approach, we will use the above requirements as a program outline. Templates allow us to solve this problem from a top down view.

   
/** this is a template for an application */

public Linkedlist {
   class level variables

   public Linkedlist() {
      ...
   }

   public LinkedList(int n, LinkedList ln) {
      ...
   }

   public void add( int num ) {
      ...
   }

   void addLast( int num) {
      ...
   }

   public void addFirst( int num ) {
      ...
   }

   public void DisplayLL() {
      ...
   }

   void Remove(int num) {
      ...   
   }

   public boolean isEmpty() {
      ...
   }

   public boolean contains( int num ) {
      ...
   }

   public void toArray(int a[]) {
      ...
   }

   public int getLast() {
      ...
   }

   public int size() {
      ...
   }

   public static void main( String args[] ) {
      ...
   }

}
   
Figure 6: Linked List Template


Logic for addFirst Method

We will use dynamic allocation to get the space for each node at run time. To accomplish this, we will use the Java new operator to allocate space for the linked list object. This is called creating an instance of the object. An example looks like:

  

LinkedList head = null ;
head = LinkedList(num, head);
                   ^     ^
                   |     |
The number to be ->+     +--- The current beginning of the 
added                         linked list
  
Figure 7: Linked List: Adding a node


The pseudocode for adding a node is:

  1. Purpose of this method:
    1. Adds a value to the beginning of the list.
    2. Create a new node
    3. Point the new node to the entry pointed to by the head
    4. Add the new value to the Newnode
    5. Point the head to the new node
We can use the above pseudocode as the next step in our stepwise refinement. We will next explore removing a node.

Logic for removing nodes

To remove a node from the Linked List, we will do the following pseudocode:

  1. Check to see if the Linked list has entries.
    • If the Linked list is empty, then there is no further processing required.
  2. Check if the value we are seeking is in the first node in the Linked list.
    • Delete that node by making the value of next the new head.
  3. Start iterating through the Linked list until the value we are seeking is found.
    • Delete that node by removing its reference from the link.
As we step through our refinement process, we will next examine the pseudocode for the Add method.

Logic for add Method

The pseudocode for the add Method is as follows:

  1. Create a new node.
  2. Check to see if the Linked list has entries.
    • If the Linked list is empty, then head will contain the reference to the new node.
  3. Else iterate through the linked list until the value to be added is less than a value already in the list.
    • At the first value in the list that is greater than the new value:
      • Insert the new value before this existing value.
As we continue to step through our refinement process, we will next examine the pseudocode for the addLast method.

Logic for addLast Method

The pseudocode for the addLast Method is:

  1. Create a new node.
  2. Iterate through the list until the end is reached and then add the new node at the tail of the list.
We will next examine the pseudocode for the DisplayLL method, as we continue to step through our refinement process.

Logic for DisplayLL Method

In the DisplayLL Method, the pseudocode is:

  1. Iterate through the list and display each element to the screen.
We will next examine the pseudocode for the isEmpty method, as we continue to step through our refinement process.

Logic for isEmpty Method

In the isEmpty Method:

  1. If the head is null, this means that the list is empty; therefore, return false.
  2. If the head is not null, this means that the list is not empty; therefore, return true.

Logic for contains Method

In the contains Method:

  1. A parameter is passed to the contains Method.
  2. Iterate through the list and find out if the passed parameter exists in the list.
  3. Return true if the value exists.
  4. Return false if the value does not exists.

Logic for toArray Method

In the toArray Method:

  1. A reference to an array is passed to the toArray Method.
  2. Iterate through the list and add each element in the list to the array.

Logic for getLast Method

In the getLast Method:

  1. Iterate through the list until the last element is found.
  2. Return the last element.

Logic for size Method

In the size Method:

  1. Iterate through the list until the last element is found.
  2. Count each element while iterating.
  3. Return the count.

Putting It All Together

When we put it all together we get code that looks like:
  
/**************************************************************
 * File: LinkedList.java
 *
 * Methods:
 *    -  public LinkedList()
 *    -  public LinkedList(int n, LinkedList ln)
 *    -  public void add( int num )
 *    -  void addLast( int num)
 *    -  public void addFirst( int num )
 *    -  public void DisplayLL()
 *    -  void Remove(int num)
 *    -  public boolean isEmpty()
 *    -  public boolean contains( int num )
 *    -  public void toArray(int a[])
 *    -  public int getLast()
 *    -  public int size()
 *    -  public static void main(String args[])
 *
 *
 *
 ***********************************************************************/

public class LinkedList {
   public int value;              // value of element
   public LinkedList next;        // reference to next
   private LinkedList head, last ;

   /** **********************************************
    *  constructor
    *
    ************************************************ */
   public LinkedList() {
      // initialize list head
      head = null;
   }

   /** **********************************************
    *  constructor
    *
    ************************************************ */
   public LinkedList(int n, LinkedList ln) {
      value = n;
      next = ln;
   }

   /** **********************************************
    *  Method: add( int num )
    *
    *  Purpose:  Adds a value to the list in sorted
    *  order.
    *
    ************************************************ */
   public void add( int num ) {
      LinkedList NewNode, NodeRef, PreviousNode = null ;

      /** ***********************************************
       *  Allocate a new node & store Num
       ************************************************** */
      NewNode = new LinkedList();
      NewNode.value = num;

      /** ***********************************************
       * If there are no nodes in the list
       * make NewNode the first node
       ************************************************** */

      if (head == null )  {
         head = NewNode;
         NewNode.next = null ;
      }
      else	{  /** Otherwise, insert NewNode at end */
         /** *********************************************
          * Initialize NodeRef to head of list
          ************************************************ */

         NodeRef = head;

           // Skip all nodes whose Value member is less
           // than Num.
         while (NodeRef != null && NodeRef.value < num)  {
            PreviousNode = NodeRef ;
            NodeRef = NodeRef.next;
         }

 	 /** **********************************************
          * Insert the node after the one pointed to
	  * by PreviousNode and before the one pointed to
	  * by NodePtr.
          **********************************************  */

         PreviousNode.next = NewNode;
         NewNode.next = NodeRef ;
      }
   }

   /** **********************************************
    *  Method: addLast( int num )
    *
    *  Purpose:  Adds a node containing the value passed
    *  in num, to the end of the list.
    *
    ************************************************ */
   void addLast( int num) {
      LinkedList NodeRef, NewNode ;
      NodeRef = head;

      /** **********************************************
       * Allocate a new node & store Num
       *
       ************************************************ */
      NewNode = new LinkedList();
      NewNode.value = num;
      NewNode.next = null ;

      /** *************************************************
       * If there are no nodes in the list
       * make NewNode the first node
       ************************************************* */
      if ( head == null )
         head = NewNode;
      else	{  // Otherwise, insert NewNode at end
           // Initialize NodePtr to head of list
         NodeRef = head;

           // Find the last node in the list
         while ( NodeRef.next != null )
            NodeRef = NodeRef.next;

              // Insert NewNode as the last node
         NodeRef.next = NewNode;
      }
   }

   /** **********************************************
    *  Method: addFirst( int num )
    *
    *  Purpose:  Adds a value to the beginning of the
    *  list.
    *
    ************************************************ */
   public void addFirst( int num ) {

      head = new LinkedList(num, head);
   }

   /** **********************************************
    * Method: DisplayLL()
    *
    * Purpose: Iterate through a non-empty linked list
    *          until all of the entries are displayed on
    *          the screen.
    *
    ************************************************ */
   public void DisplayLL() {
      LinkedList NodeRef ;
      NodeRef = head;

      // list all entries
      while (NodeRef != null) {
         System.out.println(NodeRef.value);
         NodeRef = NodeRef.next;
      }
   }

   /** **********************************************
    * Method: Remove(int num)
    *
    * The Remove function searches for a node
    * with Num as its value. The node, if found, is
    * deleted from the list and from memory.
    * 1. Check to see if the Linked list has entries.
    *    - If the Linked list is empty, then there is no
    *      further processing required.
    * 2. Check if the value we are seeking is in the first
    *    node in the Linked list.
    *    - Delete that node by making the value of next the
    *      new head.
    * 3. Start iterating through the Linked list until the
    *    value we are seeking is found.
    *    - Delete that node by removing its reference from
    *      the link.
    *
    ************************************************ */

   void Remove(int num) {
      LinkedList NodeRef, PreviousNode = null;

      /** If the list is empty, do nothing.  */
      if ( !(head == null) ) {
         NodeRef = head ;

	 /** Determine if the first node is the one. */
         if (NodeRef.value == num) {
            head = NodeRef.next;
         }
         else {
            /** Initialize NodeRef to head of list */
            NodeRef = head;


            /** *************************************
             * Skip all nodes whose value member is
             * not equal to num.
             * *************************************** */

            while (NodeRef != null  ) {
               if ( NodeRef.value != num ) {
                  PreviousNode = NodeRef;
                  NodeRef = NodeRef.next;
               }
               else {

                  /** *********************************************
                   * Link the previous node to the node after
                   * NodeRef, then delete NodeRef.
                   *********************************************** */

                  PreviousNode.next = NodeRef.next;
                  System.out.println("\nThe number " + num +
                            " sought has been found.\n") ;

                  /** quit while loop - node found   */
                  break ;

               } /** End of inner if-then-else   */
            }  /** End of while loop   */
         }  /** End of outer if-then-else   */
      }  /** End of outer if   */
   }

   /** **********************************************
    * Method: isEmpty()
    *
    * Purpose: Determine if the linked list is empty.
    *          Return:
    *              - true if linked list is not empty
    *              - false if linked list is empty
    *
    ************************************************ */
   public boolean isEmpty() {
      boolean ret ;

      if ( head == null ) {
         ret = false ;
      }
      else {
         ret = true ;
      }

      return ret ;
   }

   /** **********************************************
    * Method: contains( int num )
    *
    * Purpose: Determine if the linked list contains
    *          the passed parameter.
    *          Return:
    *              - true if linked list is not empty
    *              - false if linked list is empty
    *
    ************************************************ */
   public boolean contains( int num ) {
      LinkedList NodeRef, PreviousNode = null;
      boolean ret = false ;
      int a ;

      /** If the list is empty, do nothing.  */
      if ( !(head == null) ) {

         NodeRef = head ;

	 /** *************************************
          * Skip all nodes whose value member is
          * not equal to num.
          * *************************************** */

          while (NodeRef != null  ) {
             if ( NodeRef.value != num ) {
                PreviousNode = NodeRef;
                NodeRef = NodeRef.next;
             }
             else {

                /** *********************************************
                 * Link the previous node to the node after
                 * NodeRef, then delete NodeRef.
                 *********************************************** */

                ret = true ;
                System.out.println("\nThe number " + num +
                            " sought has been found.\n") ;

                /** quit while loop - node found   */
                break ;

            } /** End of inner if-then-else   */
         }  /** End of while loop   */
      }  /** End of outer if   */

      return ret ;
   }

   /** **********************************************
    * Method: toArray(int a[])
    *
    * Purpose: Returns an array containing all of the
    *          elements in this list in the correct
    *          order.
    *
    ************************************************ */
   public void toArray(int a[]) {
      LinkedList NodeRef, PreviousNode = null;
      int ii = 0 ;

      /** If the list is empty, do nothing.  */
      if ( !(head == null) ) {
         NodeRef = head ;

	 /** *************************************
          * Skip all nodes whose value member is
          * not equal to num.
          * *************************************** */

          while (NodeRef != null  ) {

             a[ ii ] = NodeRef.value ;


             ii++;
             NodeRef = NodeRef.next;

         }  /** End of while loop   */
      }  /** End of outer if   */

   }

   /** **********************************************
    * Method: getLast()
    *
    * Purpose: Return the last logical number in the linked
    *          list
    *
    ************************************************ */
   public int getLast() {
      LinkedList NodeRef, PreviousNode = null;
      int ret ;

      /** If the list is empty, do nothing.  */
      if ( !(head == null) ) {
         NodeRef = head ;

	 /** *************************************
          * Skip all nodes whose value member is
          * not equal to num.
          * *************************************** */

         while (NodeRef != null  ) {
            PreviousNode = NodeRef;
            NodeRef = NodeRef.next;
         }
      }

      return PreviousNode.value ;
   }

   /** **********************************************
    * Method: size()
    *
    * Purpose: Returns the size of the linked list.
    *          Return:
    *              - number in linked list if not empty
    *              - 0 if linked list is empty
    *
    ************************************************ */
   public int size() {
      LinkedList NodeRef, PreviousNode = null;
      int ret = 0 ;

      /** If the list is empty, do nothing.  */
      if ( (head != null) ) {
         NodeRef = head ;

         ret = 1 ;

         while (NodeRef.next != null  ) {
            NodeRef = NodeRef.next;

            ret++;

         }  /** End of while loop   */
      }  /** End of outer if   */

      return ret ;
   }

   public static void main(String args[]) {
      boolean ret ;
      int a , b = 0 , arr[] = new int[ 100 ];

      LinkedList pp = new LinkedList() ;

      /** **************************************
       *  Determine if the linked list is empty.
       *****************************************/
      ret = pp.isEmpty() ;

      if ( ret ) {
         System.out.println("\nThe linked list is not empty.\n") ;
      }
      else {
         System.out.println("\nThe linked list is empty.\n") ;
      }

      /** **************************************
       *  Add some entries to list.
       *****************************************/
      System.out.println("\nAdding some entries to list.\n") ;
      pp.add(0);
      pp.add(9);
      pp.add(2);
      pp.add(7);
      pp.add(1);
      pp.add(10);
      pp.add(15);
      pp.add(3);
      pp.add(8);
      pp.add(4);
      pp.add(5);
      pp.add(6);
      pp.add(11);

      System.out.println("\nThe last number in the linked list is " + pp.getLast() + ".\n") ;

      /** **************************************
       *  Display the linked list.
       *****************************************/
      pp.DisplayLL() ;

      /** **************************************
       *  Determine if the linked list contains
       *  the value 15. If it does remove 15.
       *****************************************/
      a = 15 ;
      ret = pp.contains( a ) ;
      if ( ret ) {
         System.out.println("\nThe linked list contains the number "
                  + a + ".\n") ;
         System.out.println("\nRemoving the number " + a + ".\n") ;
         pp.Remove( a ) ;
      }
      else {
         System.out.println("\nThe linked list does not contain the number "
                  + a + ".\n")  ;
      }

      /** **************************************
       *  Display the linked list.
       *****************************************/
      System.out.println("\nDisplaying the entries in the linked list.\n") ;
      pp.DisplayLL() ;

      /** **************************************
       *  Determine if the linked list contains
       *  the value 15. If it does remove 100.
       *****************************************/
      a = 100 ;
      ret = pp.contains( a ) ;
      if ( ret ) {
         System.out.println("\nThe linked list contains the number "
                  + a + ".\n") ;
         pp.Remove( a ) ;
      }
      else {
         System.out.println("\nThe linked list does not contain the number "
                  + a + ".\n")  ;
      }



      /** **************************************
       *  Determine the size of the linked list.
       *****************************************/
      a = pp.size() ;
      System.out.println("\nThe number of entries in the linked list is " + a + ".\n") ;

      System.out.println("\nThe last number in the linked list is " + pp.getLast() + ".\n") ;

      /** **************************************
       *  Use the linked list to create an array.
       *****************************************/
      pp.toArray( arr )  ;

      /** *******************************************
       *  Print to screen the elements in the array.
       **********************************************/
      b = pp.size() ;
      System.out.println("\nThe elements in array arr are.\n") ;
      for( a = 0 ; a < b ; a++ ) {
         System.out.print(" " + arr[ a ] ) ;
      }
   }
}


  
Figure 7: Linked List Code


Our Linked List API

Methods: Description
public LinkedList() Constructs an empty list.
public LinkedList(int n, LinkedList ln) This Constructor is no longer used
public void add( int num ) Inserts the specified element to this list in ascending sorted order.
void addLast( int num) Appends the given element to the end of this list.
public void addFirst( int num ) Inserts the given element at the beginning of this list.
public void DisplayLL() Displays the elements in the list to the screen
void Remove(int num) Deletes the specified element from the list.
public boolean isEmpty() Determines if the list is empty.
  • Returns true if not empty
  • Returns false if empty
public boolean contains( int num ) Determines if the specified value is in the list.
  • Returns true if the value is in the list
  • Returns false if the value is not in the list
public void toArray(int a[]) Add each element in the list to the referenced array.
public int getLast() Returns the last element in the list.
public int size() Returns the size of the list i.e., the number of elements.
public static void main(String args[]) This is the entry point of the application.

DBMS

    DataBase Management System.

inheritance

    when a class is defined, any subclass that is defined can inherit the definitions (public and/or protected) of the parent/base classes.

Java API: Linked List

    The following are the methods in the Java Linked List.

Pseudocode

    is a informal high-level description of a computer programming algorithm. It uses the structural conventions of a formal programming language, but it is intended for human reading rather than machine language for computer reading.

requirement

    In this instance, a specification that documents the functions, performance, design constraints and attributes of a program to be delivered.

Template

    is a unique class or pattern that can be used to build other software code.

Java API: Linked List Method Summary
void add(intindex, Objectelement) Inserts the specified element at the specified position in this list.
boolean add(Object) Appends the specified element to the end of this list.
boolean addAll Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.
boolean addAll Inserts all of the elements in the specified collection into this list, starting at the specified position.
void addFirst Inserts the given element at the beginning of this list.
void addLast Appends the given element to the end of this list.
void clear Removes all of the elements from this list.
Object clone Returns a shallow copy of this LinkedList.
boolean contains Returns true if this list contains the specified element.
Object get Returns the element at the specified position in this list.
Returns the first element in this list.
Object Returns the last element in this list.
int indexOf Returns the index in this list of the first occurrence of the specified element, or -1 if the List does not contain this element.
int lastIndexOf(Object) Returns the index in this list of the last occurrence of the specified element, or -1 if the list does not contain this element.
ListIterator listIterator(intindex) Returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.
Object remove Removes the element at the specified position in this list.
boolean remove(Objecto) Removes the first occurrence of the specified element in this list.
Object removeFirst Removes and returns the first element from this list.
Object removeLast Removes and returns the last element from this list.
Object set(intindex, Objectelement) /b> Replaces the element at the specified position in this list with the specified element.
int size Returns the number of elements in this list.
Object[] toArray Returns an array containing all of the elements in this list in the correct order.
Object[] toArray(Object) Returns an array containing all of the elements in this list in the correct order.





[
HOME] Consulting Design Maintenance Project Testing Training Turnkey Java C++ SQL HTML JavaScript ]

© 2002 - 2011 All Rights Reserved Total Application Works