Let us now learn about STL which stands for Standard Template Library. Just as the words say it means a set of templates(basic building blocks of code) for data structs and algorithms.
C++ Standard Template Library
STL consists of three main components
1) Algorithms2) Containers
3) Iterators
1. STL Algorithms
i) Sorting : One of the basic algorithms used in almost any system is sorting, C++ STL has a functionwhich does the same, here is the prototype
sort(first_iterator, last_iterator)
http://codepad.org/C3YlUxcE
ii) Searching : Another very important tool in software engineering is searching for an element in a
given set of elements.
binary_search(start, end, valueToSearch)
http://codepad.org/TpWcqm0i
2. STL Containers
i) Vector : It is similar to an array expect with the ability to resize itself when an element is added ordeleted. Below is an example of an vector.
http://codepad.org/eTNBnqMZ
ii) List : This container has the ability to store data in non contagious memory locations as apposed to
a Vector or Array which require contiguous memory locations. Below is an example code of a
List.
http://codepad.org/YnXCvuLQ
iii) Queue : Queue is a data structure which follows the principle of FIFO(First In First Out). It is
similar to the queue discussed in the other page of this blog.
http://codepad.org/MivtnZXP
iv) Stack : Stack is another data structure which follows the principle of LIFO(Last In First Out). It is
also same as the one explained in the other page of this blog.
http://codepad.org/zZIai6hg
v) Map : Several applications need a fast look up of data, Map is one such data structure which gives
an O(1) computational complexity.
http://codepad.org/SCVAHB3R
No comments:
Post a Comment