Linear Data Structures 2.0

Linear Data Structures 2.0 - CSE 2011 Prof. J. Elder - 49 -...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 46 - Queue Interface in Java • Java interface corresponding to our Queue ADT • Requires the definition of class EmptyQueueException public interface Queue { public int size() ; public boolean isEmpty() ; public Object front() throws EmptyQueueException ; public void enqueue(Object o) ; public Object dequeue() throws EmptyQueueException ; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 47 - Linked Lists Chapters 3.2 – 3.3
Background image of page 2
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 48 - Linked Lists By virtue of their random access nature, arrays support non-structural read/write operations (e.g., get(i) , set(i) ) in O(1) time. Unfortunately, structural operations (e.g., add(i,e) remove(i) ) take O(n) time. For some algorithms and inputs, structural operations may dominate the running time. For such cases, linked lists may be more appropriate.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Last Updated: 12-01-17 9:52 AM
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 2011 Prof. J. Elder - 49 - Singly Linked List (§ 3.2) • A singly linked list is a concrete data structure consisting of a sequence of nodes • Each node stores – element – link to the next node next elem node A B C D ! Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 50 - Example Java Class for Singly-Linked Nodes public class Node { // Instance variables: private Object element ; private Node next ; /** Creates a node with null references to its element and next node. */ public Node() { this ( null , null ); } /** Creates a node with the given element and next node. */ public Node(Object e, Node n) { element = e; next = n; } // Accessor methods: public Object getElement() { return element ; } public Node getNext() { return next ; } // Modifier methods: public void setElement(Object newElem) { element = newElem; } public void setNext(Node newNext) { next = newNext; }...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

Linear Data Structures 2.0 - CSE 2011 Prof. J. Elder - 49 -...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online