Searching And Sorting Linked Lists Computer Science Homework Help

The instructions and accompanying files will be uploaded due to formatting issues. the first file is the lab. the following is the UnorderedLinkedListInt class.

public class UnorderedLinkedListInt extends LinkedListIntClass{

  public UnorderedLinkedListInt(){

    super();

  }

  public boolean search(int searchItem){

    LinkedListNode current;

    current = first;

    while (current != null){

      if (current.info == searchItem)

        return true;

      else

        current = current.link;

    }

    return false;

  }

  public void insertFirst(int newItem){

    LinkedListNode newNode;

    newNode = new LinkedListNode(newItem, first);

    first = newNode;

    if (last == null)

      last = newNode;

    count++;

  }

  public void insertLast(int newItem){

    LinkedListNode newNode;

    newNode = new LinkedListNode(newItem, null);

    if (first == null){

      first = newNode;

      last = newNode;

    }

    else{

      last.link = newNode;

      last = newNode;

    }

    count++;

  }

  public void deleteNode(int deleteItem){

    LinkedListNode current;

    LinkedListNode trailCurrent;

    boolean found;

    if (first == null)

      System.err.println(“Cannot delete from an empty list.”);

    else{

      if (first.info == deleteItem){

        first = first.link;

        if (first == null)

          last = null;

        count–;

      }

      else{

        found = false;

        trailCurrent = first;

        current = first.link;

        while (current != null && !found){

          if (current.info == deleteItem)

            found = true;

          else{

            trailCurrent = current;

            current = current.link;

          }

        }

        if (found){

          count–;

          trailCurrent.link = current.link;

          if (last == current)

            last = trailCurrent;

        }

        else

          System.out.println(“Item to be deleted is not in the list.”);

      }

    }

  }

}

Also, do not worry about input validation in the Client. i will take care of that myself, thanks!

No matter what kind of paper writing service you need, we’ll get it written. Place Your Order Now!
× How can I help you?