A Data Structure Bestiary Views from around the
A Data Structure Bestiary Views from around the web
Arrays
Strings
Tuples
Singly-linked lists
Simple list implementation n Sample methods: n n n Test if list is empty Look at the value in a node Go to the next node (if any) Add a new node to the beginning Remove a node from the beginning n n class Node<V> { V value; Node next; // constructor… // methods… } class List { Node<V> head = null; // methods… }
Node n class Node<V> { private V value; private Node<V> next; Node(V value, Node next) { this. value = value; this. next = next; } V value() { return value; } boolean has. Next() { return next != null; } Node next() { return next; } }
List n public class List<V> { private Node<V> head = null; boolean is. Empty() { return head == null; } Node<V> first() { return head; } void add(V val) { head = new Node<V>(val, head); } void remove() throws Null. Pointer. Exception { head = head. next; } }
Doubly-linked lists
Stacks
Queues
Priority queues
Deques
Maps
Sets
Hash tables (buckets)
Hash maps (buckets)
Hash maps (open addressing)
Binary trees
Search trees
Heaps
The other kind of heap free 0 next = 0 1 size = 2 2 next = 0 3 size = 6 4 ////// 5 ////// 6 ////// 7 ////// 8 next = 13 9 size = 3 10 11 next = 2 12 size = 5 13 14 15 16 next = 0 17 size = 4 18 ////// 19 //////
Trees
Parse trees
Tries
Diected graphs (Digraphs)
Undirected graphs
Data structures as tools Arrays (or lists) alone A more complete toolset
The End
- Slides: 29