{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Linear Data Structures 2.1

Linear Data Structures 2.1 - Example Java Class for...

Info icon This 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 - 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 }
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
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
Image of page 2
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.
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
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the 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