Useful Data Structures in C and Java Useful

  • Slides: 7
Download presentation
Useful Data Structures in C++ and Java

Useful Data Structures in C++ and Java

Useful Data Structures in C++ (1) • Templates are C++’s mechanism to define abstract

Useful Data Structures in C++ (1) • Templates are C++’s mechanism to define abstract objects which can be parameterized by type. • The C++ Standard Template Library (STL) provides implementations of many useful data structures, such as stacks, queues, dictionaries, priority queues, and sets.

Useful Data Structures in C++ (3) • Stack – S. push(), S. top(), S.

Useful Data Structures in C++ (3) • Stack – S. push(), S. top(), S. pop(), S. empty(). You should always top on pop because top returns but does not remove the element on top, while pop removes but does not return the element. • Queue – Q. front(), Q. back(), Q. push(), Q. pop(), and Q. empty(). Queue have the same idiosyncrasies as stack.

Useful Data Structures in C++ (3) • Dictionary – STL contains a wide variety

Useful Data Structures in C++ (3) • Dictionary – STL contains a wide variety of containers, including hash_map, a hashed associative container binding keys to data items. Methods include H. erase(), H. find(), and H. insert() • Priority Queue – Declared priority-queue<int> Q; , methods include Q. top(), Q. push, Q. pop(), and Q. empty(). • Set – Sets are represented as sorted associative containers, declared set<key, comparison> S; . Set algorithms include set_union and set_intersection, as well as other standard set operators.

Useful Data Structures in Java (1) • Useful standard Java objects appear in the

Useful Data Structures in Java (1) • Useful standard Java objects appear in the java. util package. Below are some useful objects related to data structures. • To use java. util include import java. util. *; at the beginning of your program to improt the whole package.

Useful Data Structures in Java (2) Data Structure Stack Abstract class No Queue List

Useful Data Structures in Java (2) Data Structure Stack Abstract class No Queue List Concrete class Stack Array. List, Linked. List Dictionary Map Hash. Map, Hashtable Priority Sorted. Map Tree. Map Queue Set Hash. Set Methods pop, push, empty, peek add, remove, clear put, get, contains first. Key, last. Key, heap. Map add, remove, contains

Useful Data Structures in Java (3) • You can declare a data structure object

Useful Data Structures in Java (3) • You can declare a data structure object with an interface or abstract class and instantiate it using a concrete class, like Map my. Map = new Hash. Map(); • Or you can declare a data structure object and instantiate it with a concrete class, like Hash. Map my. Map = new Hash. Map();