Download presentation

Presentation is loading. Please wait.

Published byStephen Higgerson Modified over 2 years ago

2
Data Structures Simple data type –int, char, long Reference data type –Integer, String, Composite data type == Data Structure –Collection of elements of possibly different types –Class

3
Linear Data Structures Elements have an order Each element has a predecessor and a successor One element is first, and one is last Examples: –List –Stack –Queue

4
Hierarchical Data Structures Elements relate in 1:many relationships –Trees One root at the base of the structure One or more leaves most distant from the root 0, 1, or many internal nodes (neither root, nor leaf) Each node has: –a unique predecessor, and –0, 1, or many successors

5
Graph Data Structure Elements may have many:many relationships with other elements No constraints on numbers of predecessors or successors

6
Arrays [0] [1] [2] [3] [4] [5] [6] [7] Addr. of a[2] Addr. of a[0] + 2*element-size What’s not to like? 8 advantages: Create one of any size while the program is running. Efficient; only overhead is stored length. Constant-time element access.

7
Lists An ordered collection of nodes Node contains: –Information (“data”) –Identity of the successor (“next”) –Identity of the predecessor (“previous”)

8
List Operations/Methods first() last() next() previous() add() / add( pos ) remove() / remove( pos ) append() get() / get( pos ) set() / set( pos ) exists() /contains() /isOnList() size()

9
From Prof. Heliotis, 2006 Linked List Starts empty; grows as things are added no wasted space. Insertion / removal from front in constant time… advantages:

10
From Prof. Heliotis, 2006 Link Nodes, Basic Types class LinkNode { int value; LinkNode next; LinkNode( int v ) { value = v; } // other methods... }; 7 new LinkNode( 7 )

11
From Prof. Heliotis, 2006 Link Nodes, Generic Contents class LinkNode { E value; LinkNode next; LinkNode( E v ) { value = v; } // other methods... }; new LinkNode( obj ) HeartObj

12
From Prof. Heliotis, 2006 Insert insertAfter( a, c ); a c b X

13
From Prof. Heliotis, 2006 Deletion remove( c ); a c b Where is a?

14
From Prof. Heliotis, 2006 Deletion, Take 2 removeNodeFollowing( a ); a c b X

15
From Prof. Heliotis, 2006 Doubly Linked Lists (code) class DLinkNode { int value; DLinkNode previous, next; DLinkNode( int v ) { value = v; } // other methods... };

16
From Prof. Heliotis, 2006 Doubly Linked Lists Now it is possible to directly delete a link node!

17
From Prof. Heliotis, 2006 A LinkedList Class, Take 1 class LinkedList { LinkNode start; }; start

18
From Prof. Heliotis, 2006 A LinkedList Class, Take 2 class LinkedList2 { LinkNode start; LinkNode end; }; start end

19
From Prof. Heliotis, 2006 A LinkedList Class, Take 3 class DLinkedList { DLinkNode start; DLinkNode end; }; start end

20
Class Exercise/Discussion What would a linked list’s responsibilities be? What specific methods might it implement? How would you implement insertion? –(singly linked list) How would you implement removal? –(singly linked list)

Similar presentations

OK

Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.

Stacks, Queues, and Deques. A stack is a last in, first out (LIFO) data structure –Items are removed from a stack in the reverse order from the way they.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on cross-sectional study advantages and disadvantages Cornea anatomy and physiology ppt on cells Dynamic scattering liquid crystal display ppt online Ppt on climate of rajasthan Ppt on personality development in hindi Ppt on waxes structure Ppt on standing orders Ppt on eddy current brake Ppt on peak load pricing and price Download ppt on transportation in human beings what is the largest