Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection.

Similar presentations


Presentation on theme: "Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection."— Presentation transcript:

1 Lecture 14 Linked Lists 14-1 Richard Gesick

2 Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection (i.e., a sequence) of nodes, connected by reference links (“chained together”). It can be singly or doubly linked A linked list is appropriate when the number of data elements is unpredictable. Linked lists become full only when the system has insufficient memory. 14-2

3 Nodes A self-referential class contains a member that refers to an object of the same class type. In the class declaration Next references an object of type Node, an object of the same type being declared. Next is referred to as a link. class Node { public string data; public Node next ; } 14-3

4 Common tasks include: Inserting to the front Inserting to the end Inserting in between the front/end Deleting Searching Sorting Each of these tasks takes different amounts of time depending upon how the linked list is implemented 14-4

5 A Linked List A backslash indicates a null link. Not setting the link in the last node of a list to null is a logic error. 14-5

6 Inserting at the front Method InsertFront places a new node at the front of the list through the following process: 1.Create a new Node 2.Assign new data to Node data 3.Assign the current head node’s address/pointer to the new Node 4.Set the head node’s address/pointer to the new Node 14-6


Download ppt "Lecture 14 Linked Lists 14-1 Richard Gesick. Linked Lists Dynamic data structures can grow and shrink at execution time. A linked list is a linear collection."

Similar presentations


Ads by Google