Linked List • What is the linked list? CSED233: Data Structures (2013F) . Adata structure consisting of a sequence of nodes . Each node is composed of data and link(s) to other nodes. Lecture5: Linked Lists • Properties . Linked lists can be used to implement several other common abstract Bohyung Han data types, such as stacks and queues CSE, POSTECH . The elements can easily be inserted or removed without reallocation
[email protected] or reorganization of the entire structure . Linked lists allow insertion and removal of nodes at any point in the list in constant time. Simple linked lists do not allow random access to the data. http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html CSED233: Data Structures 2 by Prof. Bohyung Han, Fall 2013 Singly Linked Lists The Node Class for Singly Linked List • A singly linked list is a concrete data structure consisting of a // Node class sequence of nodes Node public class Node • Each node stores { Defines element and link private Object element; . next Element(s) private Node next; . Link to the next node // Constructors Creates a node with null, which references public Node() to its element and next node element { this(null, null); } public Node(Object e, Node n) { Creates a node with given element element = e; and next node next = n; A B C D } CSED233: Data Structures CSED233: Data Structures 3 by Prof. Bohyung Han, Fall 2013 4 by Prof. Bohyung Han, Fall 2013 The Node Class for Singly Linked List Inserting a Node at the Head public Object getElement() • head { Operation sequence .