Day-15-LinkedLists - public boolean add(E e linkLast(e...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE116 / CSE504 Introduction to Computer Science II Dr. Carl Alphonce 343 Davis Hall [email protected] Office hours: Thursday 12:00 PM – 2:00 PM Friday 8:30 AM – 10:30 AM OR request appointment via e-mail
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
PROFESSIONALISM Turn off and put away electronics: cell phones pagers laptops tablets etc. © Dr. Carl Alphonce
Image of page 2
Last class linked lists Today java.util.LinkedList exercise Coming up asymptotic notation LRStruct Stack/Queue Trees/BST/Heap ROADMAP
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
public class LinkedList<E> extends ... implements ... { int size = 0; /* Pointer to first node. * Invariant: (first == null && last == null) || * (first.prev == null && first.item != null) */ Node<E> first; /* Pointer to last node. * Invariant: (first == null && last == null) || * (last.next == null && last.item != null) */ Node<E> last; /* Constructs an empty list. */ public LinkedList() { } ... }
Image of page 4
/** Appends the specified element to the end of this list. * @param e element to be appended to this list
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: */ public boolean add(E e) { linkLast(e); return true; } /* Links e as last element. */ void linkLast(E e) { final Node<E> l = last; final Node<E> newNode = new Node<>(l, e, null); last = newNode; if (l == null) first = newNode; else l.next = newNode; size++; modCount++; } private static class Node<E> { E item; Node<E> next; Node<E> prev; Node(Node<E> prev, E element, Node<E> next) { this.item = element; this.next = next; this.prev = prev; } } Exercises 1. Draw an object diagram showing: LinkedList<String> names = new LinkedList<String>() 2. Draw object diagrams showing what happens here: String s1 = “Mal”; names.add(s1); 3. Draw object diagrams showing what happens here: String s2 = “River”; names.add(s2);...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern