H-SC COMS 262 - Lecture 18 - Linked Lists

Unformatted text preview:

Linked ListsTopicsThe LinkedList ClassLinkedList Data MembersThe LinkedListNode ClassLinkedListNode Data MembersLinkedListNode Member FunctionsSlide 8Validity Requirements of a Linked ListSlide 10Linked ListsLecture 18Mon, Mar 1, 200401/15/19 List Implementations 2TopicsThe LinkedList classThe LinkedListNode classValidity requirementsThe implementation of the member functions01/15/19 List Implementations 3The LinkedList ClassFor each element of the list, a node is allocated dynamically when that element is added to the list.The LinkedList always uses exactly the amount of memory it needs.The LinkedList is more efficient than the ArrayList in some ways and less efficient in others.01/15/19 List Implementations 4LinkedList Data Membersint sizeThe number of elements in the list.LinkedListNode* headA pointer to the first node (which contains the first element).01/15/19 List Implementations 5The LinkedListNode ClassWe create a separate class, LinkedListNode, as a data type that stores one element of a LinkedList.Each node contains a pointer that links it to the next node.01/15/19 List Implementations 6LinkedListNode Data MembersA linked list node has two components.T dataThe list element ai.LinkedListNode* nextA pointer that points to the node containing list element ai + 1. Or, NULL if ai is the last element.01/15/19 List Implementations 7LinkedListNode Member FunctionsThe node constructors are private.They can be invoked only by friend classes. Public interface T& Value();Returns a reference to the data member of the node. LinkedListNode* Next();Returns a copy of the pointer to the next node.01/15/19 List Implementations 8The LinkedListNode ClassThe LinkedListNode classlinkedlistnode.h01/15/19 List Implementations 9Validity Requirements of a Linked Listsize >= 0.If size == 0, then head == NULL.If size > 0, then head != NULL.For every i from 1 to size – 1, in node i, next != NULL.In node size, next == NULL.01/15/19 List Implementations 10The LinkedList ClassThe LinkedList


View Full Document

H-SC COMS 262 - Lecture 18 - Linked Lists

Download Lecture 18 - Linked Lists
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 18 - Linked Lists and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 18 - Linked Lists 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?