Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes 21CS101T (OODP) C++

Rating
-
Sold
-
Pages
6
Uploaded on
16-03-2023
Written in
2022/2023

This document is made by top professors in the university which is very effective to learn.C++ tutorial can be learned within a week become a pro with these notes.All the best guys.

Institution
Course

Content preview

OODP UNIT 05
07 December 2022 04:06 AM



1. STL CONTAINERS:

• STL stands for Standard Template Library
• In 1994, STL was adopted as a part of ANSI & ISO standard C++
• So, they developed a set of general purpose templatized classes (data structures) and
functions (algorithms) that could be used as a standard approach for storing and processing
data
• Therefore, STL is a collection of generic classes and functions.
• The components of STL are now a part of standard c++ library defined in the namespace std
• STL contains - Containers, Algorithms, Iterators
• Algorithms use iterators to interact with objects stored in containers




• Containers - a way that stored data is organised in memory (as array)
• Algorithms - procedures applied to containers to process their data (search, sort, merge, copy)
• Iterators - generalization of concept of pointers (incremented to point to next element in
array)

CONTAINERS:

• Containers are a way that stored data is organised in the memory.
• Data in memory is organised in the form of arrays.
• There are mainly three types of STL containers:




SEQUENCE CONTAINERS:

• Can store elements is a linear sequence
• Each element is related to other elements by its position along its line

, • STL provides 3 types of sequence containers
○ Vector
○ List
○ Deque

VECTOR:

• Syntax: vector<of what>
• Acts as an alternative for built in array function
• A vector is self grown
• Vector container is similar to array with an exception that it automatically manages it's storage
size

Example:

#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v; //create a vector of ints
v.push_back(10); //put values at end of array
v.push_back(11);
v.push_back(12);
v.push_back(13);
v[0] = 20; //replace with new values
v[3] = 23;
for(int j=0; j<v.size(); j++) //display vector contents
cout << v[j] << ‘ ‘; //20 11 12 23
cout << endl;
return 0;
}

LIST:

• Syntax: std::list<type> larg;
• An STL list container is a doubly linked list, in which each element contains a pointer not only
to the next element but also to the preceding one. The container stores the address of both
the front (first) and the back (last) elements, which makes for fast access to both ends of the
list.
• Lists are appropriate when you will make frequent insertions and deletions in the middle of
the list.
• Not suitable for random access , only vector or deque is suitable for random access

Example:


#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> l = {1,2,3,4,5};
list<int>::iterator it = l.begin();
l.insert (it+1, 100); // insert 100 before 2 position
/* now the list is 1 100 2 3 4 5 */
list<int> new_l = {10,20,30,40}; // new list new_l.insert (new_l.begin() , l.begin(), l.end());
/* insert elements from beginning of list l to end of list l
before 1 position in list new_l */

Written for

Institution
Course

Document information

Uploaded on
March 16, 2023
Number of pages
6
Written in
2022/2023
Type
Class notes
Professor(s)
Dr.m.subramaniam
Contains
All classes

Subjects

$8.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
parthiburk

Get to know the seller

Seller avatar
parthiburk SRM UNIVERSITY
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions