Presentation is loading. Please wait.

Presentation is loading. Please wait.

Useful Data Structures in C++ and Java. Useful Data Structures in C++ (1) Templates are C++’s mechanism to define abstract objects which can be parameterized.

Similar presentations


Presentation on theme: "Useful Data Structures in C++ and Java. Useful Data Structures in C++ (1) Templates are C++’s mechanism to define abstract objects which can be parameterized."— Presentation transcript:

1 Useful Data Structures in C++ and Java

2 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.

3 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.

4 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 Q;, methods include Q.top(), Q.push, Q.pop(), and Q.empty(). Set – Sets are represented as sorted associative containers, declared set S;. Set algorithms include set_union and set_intersection, as well as other standard set operators.

5 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.

6 Useful Data Structures in Java (2) Data Structure Abstract class Concrete class Methods StackNoStackpop,push, empty, peek QueueListArrayList, LinkedList add, remove, clear DictionaryMapHashMap, Hashtable put, get, contains Priority Queue SortedMapTreeMapfirstKey, lastKey, heapMap Set HashSetadd, remove, contains

7 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 myMap = new HashMap(); Or you can declare a data structure object and instantiate it with a concrete class, like HashMap myMap = new HashMap();


Download ppt "Useful Data Structures in C++ and Java. Useful Data Structures in C++ (1) Templates are C++’s mechanism to define abstract objects which can be parameterized."

Similar presentations


Ads by Google