Algorithms and OOD (CSC 207 2014F) : EBoards

CSC207.01 2014F, Class 34: Doubly-Linked Lists


Overview

Preliminaries

Admin

** Missing: Way too many students: RHB

Upcoming Work

Cool Upcoming Events on Campus

Extra Credit

Academic

Peer Support

Questions

Review of our implementation of singly-linked lists

Effects of the previous Operation

Here's a typical implementation of the previous operation.

    public T previous()
      throws NoSuchElementException
    {
      failFast();
      if (!this.hasPrevious())
        throw new NoSuchElementException();
      Node current = SimpleLinkedList.this.front;
      while (current.next != this.cursor)
        current = current.next;
      this.cursor = current;
      this.pos--;
      return this.cursor.next.data;
    } // previous()

Another strategy: You can use the position field to identify how many times you have to move forward.

    --this.pos;
    for (i = 0; i < this.pos; i++)
      current = current.next;

How do you implement hasPrevious?

Discuss with partner:

Removing elements

    // State:       alpha beta gamma
    //                        ^
    // We know that we've moved forward.
    it.remove()

Thoughts

Discuss with partner:

Doubly-linked lists

Discuss with partner

Circularly-linked lists