150 likes | 253 Views
COP 3530 Data Structures & Algorithms. Discussion Session 6 by Eyup. Outline. Linear lists - Array representation linearList arrayList iterator STL in C++ An example of bidirectional iterator Usage in STL algorithms Operator overloading. The abstract class linearList.
E N D
COP 3530Data Structures & Algorithms Discussion Session 6 by Eyup
Outline • Linear lists - Array representation • linearList • arrayList • iterator STL in C++ • An example of bidirectional iterator • Usage in STL algorithms • Operator overloading
Array representation • List = {5, 2, 4, 8, 1} • Insertion and removal
Iterators in C++ • Points to an element of an object • Defined in STL • Five categories. All support ==, !=, *, ++ • Input : Read access • Output: Write access • Forward: Read and write • Bidirectional: -- • Random access: +=, -=, +, -, <, >, <=, >=, []
Using iterators • To be added into arrayList • Initialization • STL algorithms
STL algorithms • Reverse • Sort
Operator overloading • Arithmetic operators • Relational operators • I/O operators • Constructors and conversions
References • http://www.cplusplus.com/reference/std/iterator/ • http://www.cplusplus.com/reference/algorithm/ • http://www.cplusplus.com/reference/stl/ • Data structures, algorithms, and applications in C++, SartajSahni. 2nd ed. • http://www.cs.duke.edu/csed/tapestry/howtoe.pdf • http://www.cplusplus.com/doc/tutorial/classes2/