Algorithms and OOD (CSC 207 2014F) : EBoards

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


Overview

Preliminaries

Admin

Upcoming Work

Cool Upcoming Events on Campus

Extra Credit

Academic

Peer Support

Questions

Doubly-linked lists

Discuss with partner

Question one: Where do we put the cursor?

Let's write pseudo-Java (not all of the syntax will be perfect

    public class DoublyLinkedIterator<T>
    {
      Node<T> cursor;
      int pos;
      boolean forward;

      public T next()
      {
        failFast();
        if (!this.hasNext())
          throw new SomeSillyThingException()
        this.cursor = this.cursor.next;
        forward = true;
        return this.cursor.data;
      } // next()

      public T previous()
      {
        failFast();
        if (!this.hasPrevious())
          throw new SomeSillyThingException()
        this.cursor = this.cursor.previous;
        forward = false;
        return this.cursor.next.data;
      } // previous()

      public void add(T val)
      {
        failFast();
        Node<T> newnode = new Node(this.cursor, val, this.cursor.next); // (prev,val,next)
        this.cursor.next = newnode;
        newnode.next.prev = newnode;
        this.cursor = newnode;
      } // add(T)

      public void remove()

      public void set(T val)
    }

Circularly-linked lists