Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.

Similar presentations


Presentation on theme: "1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees."— Presentation transcript:

1 1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees

2 2 Introduction Dynamic data structures –Grow and shrink at execution time –Several types Linked lists Stacks Queues Binary trees

3 3 Self-Referential Classes Self-referential class –Contains instance variable referring to object of same class class Node { private int data; private Node nextNode; // reference to next linked node } Member nextNode is a link –nextNode “links” a Node object to another Node object

4 4 Self-Referential Classes (cont.) Self-referential-class objects linked together. 1510

5 5 Dynamic Memory Allocation Dynamic memory allocation –Obtain more memory at execution time to store new objects Declaration and class-instance creation expression Node nodeToAdd = new Node ( 10 );

6 6 Linked Lists Linked list –Linear collection of self-referential classes (nodes) –Connected by reference links –Nodes can be inserted and deleted anywhere in linked list –Last node is set to null to mark end of list..\..\week14\linkedlist

7 7 Linked Lists (cont.) Linked list graphical representation. firstNode... HD Q lastNode

8 8 Linked Lists (cont.) Graphical representation of operation insertAtFront. firstNode 711 12 711 12 new Listnode firstNode new Listnode (a) (b)

9 9 Linked Lists (cont.) Graphical representation of operation insertAtBack. firstNode 12 new Listnode (a) (b) firstNodenew Listnode lastNode 7115 127115

10 10 Linked Lists (cont.) Graphical representation of operation removeFromFront. firstNode 12 (a) (b) 7115 127115 lastNode firstNode removeItem

11 11 Linked Lists (cont.) Graphical representation of operation removeFromBack. 12 (a) (b) lastNode 7115 127115 lastNode firstNode removeItem firstNodecurrent

12 12 Stacks Stack –Constrained version of a linked list Add and remove nodes only to and from the top of the stack –Push method adds node to top of stack –Pop method removes node from top of stack..\..\week14\linkedlist

13 13 Queues Queue –Similar to a supermarket checkout line –Nodes inserted only at tail (back) Method enqueue –Nodes removed only from head (front) Method dequeue..\..\week14\queue


Download ppt "1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees."

Similar presentations


Ads by Google