Chapter 1 Abstract Data Type and Introduction To STL (Part 1)
Chapter 1 Abstract Data Type and Introduction To STL (Part 1)
A data structure is a storage that is used to store and organize data. It is a way of
arranging data on a computer so that it can be accessed and updated efficiently. It is
The choice of a particular data model depends on two considerations. First, it must
be rich enough in structure to mirror the actual relationships of the data in the real
world. On the other hands, the structure should be simple enough that one can
effectively process the data when necessary.
The reason for learning about data structures is because adding structure to
our data can make the algorithms much simpler, easier to maintain, and often faster.
Data structure also describes the relationship among the elements in addition to
memory storage. The data appearing in the data structure are processed by means of
certain operations. The four operations that play a major role are inserting, deleting,
traversing and searching.
Other than that, sorting and merging are two additional operations used in special
situations.
Abstract Data Types
In our program models, data structures are described by abstract data types (ADTs)
We can create data structures or user-defined data types with the associated
operations to solve problems.
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by
a set of values and a set of operations.
The definition of ADT only mentions what operations are to be performed but not
how these operations will be implemented.
Examples: Array, Vector, List, Queue, Stack, Table, Tree and many more.
Abstract Data Types (cont.)
Abstract Data Types (cont.)
A stack is a last-in first-out (LIFO) linear structure where items can only be added and
removed from one end.
TOP – return the value of the item at the top of the stack
Notice these simply describe the things/what we can do, not how they are done.
These details will be reserved for implementation.
Standard Template Library
STL Components
function objects.
iterators
These can be used with any built-in type and with any function objects
This allows the use of static binding polymorphism (as opposed to run-time or
dynamic binding polymorphism) which is frequently more efficient.
Standard Template Library : Container
A container is a data structure that is typically designed to hold objects of the same
type and is a way stored data is organized in memory, e.g., an array of elements.
A number of these methods are common to all containers, while some are more
specific to the container they are defined in.
The data stored in containers can be of any type and must supply some basic
methods and operations.
public: return 0;
MyClass(){ }
head = NULL;
}
Node* createNode(){
Node *n = new Node();
cout<<"Enter a number: ";
cin>>n->data;
n->next = NULL;
return n;
}
};
Standard Template Library : Iterators
These capabilities make iterators a major feature that allows the generality of the
STL.
Standard Template Library : Iterators
Algorithms in the STL are procedures that are applied to containers to process their
data, for example search for an element in an array, or sort an array.
Each is implemented to require a certain level of iterator (and therefore will work on
any container that provides an interface by iterators)
• Sequence
Containers
Container • Derived Containers
• etc
• begin(), end() …
STL Iterator
• prev(), next() …
• sorting, searching..
Algorithm
• min, max..
End of Part 1
c l a s s . . !
See you in n e x t