Linear Data Structures 2.1

Linear Data Structures 2.1 - Last Updated: 12-01-17 9:52 AM...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 51 - Example Java Class for Singly-Linked List public class SLinkedList { // Instance variables: protected Node head ; //head node of list protected Node tail ; //tail node of list protected long size ; //number of nodes in list /** Default constructor that creates an empty list. */ public SLinkedList() { head = null ; tail = null ; size = 0 ; } // update and search methods go here … } Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 52 - Inserting at the Head 1. Allocate a new node 2. Insert new element 3. Have new node point to old head 4. Update head to point to new node 5. If list was initially empty, have to update tail as well. tail tail tail Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 53 - Removing at the Head 1. Update head to point to next node in the list 2. Allow garbage collector to reclaim the former first node 3. If list is now empty, have to update tail as well....
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.1 - Last Updated: 12-01-17 9:52 AM...

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

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