SlideShare a Scribd company logo
1 of 18
Download to read offline
STL
Standard Template Library 
• Standard Template Library 
template 
standard 
• container 
‘sequentieel’ 
‘associatief’ 
empty() size() 
• iterator 
vgl. pointer 
*p p++ == 
• algoritme 
zoeken, tellen 
kopiëren, reverse 
sorteren 
heap 
31 
77 
67 
35 
02 
- 
c.begin() 
c.end()
STL container 
sequential 
vector array, dynamisch 
list lijst, dubbel verbonden 
deque array, tweezijdige 
associative 
set verzameling 
map sleutel+waarde paren 
multimap .. meerwaardig 
adaptor 
priority_queue (niet list) 
queue rij (niet vector) 
stack stapel
STL vector 
#include <vector> 
int main() { 
vector<int> v; int i; 
for (i=0; i<10; i++) v.push_back(i); 
cout << v.size() << endl; 
for (i=0; i<10; i++) 
cout << v[i] << “ ”; 
cout << endl << v.front() 
<< “ ” << v.back() << endl; 
vector<int>::iterator p = v.begin(); 
while ( p != v.end() ) 
{ cout << *p << “ ”; p++; } 
return 0; 
}
STL adaptor, map 
#include <vector> 
#include <stack> 
int main() { 
stack<vector<int> > st; int i; 
for (i=0; i<10; i++) st.push(i); 
while ( !st.isempty() ) 
{ cout << st.top() << “ ”; st.pop(); } 
return 0; 
} 
#include <map> 
#include <string> 
int main() { 
map<string,int> mp; 
mp[“tim”] = 3; 
cout << mp[“tim”] << “ ” << mp[“bob”]; 
return 0; 
} 
map<string,int>::iterator 
p = mp.find(“bob”); 
spatie
abstracte datatypen
abstract data type 
ADT 
test 
in 
out
lijsten 
3 
6 
-1 
7 
6 
lijsten linear lists ADT vs. implementatie 
•list 
•double ended queue “deque” 
•stapel stack LIFO 
•rij queue FIFO data type elementen hier niet belangrijk (bij sommige adt’s wél)
lijsten 
3 
6 
-1 
7 
6 
ADT linear list 
first 
front/head 
last 
back/tail 
position 
•create 
•is empty 
•insert 
at/from front, back, position 
(?) before/after 
•delete 
at … (?) new position 
•value at position 
•search value 
return position (?) not found 
‘abstract’ 
data elementen 
lijst 
data types 
•element 
•position 
•list 
•boolean
lijsten 
3 
6 
-1 
7 
6 
ADT double ended queue 
first 
front/head 
last 
back/tail 
position 
•create 
•is empty 
•insert 
•delete 
•value at front, back (?) when empty 
‘abstract’ 
data elementen 
lijst 
data types 
•element 
•position 
•list 
•boolean
lijsten 
ADT double ended queue 
operation 
common name(s) 
Ada 
C++ 
Java 
Perl 
PHP 
Python 
Ruby 
Javascript 
insert element at back 
inject, snoc 
Append 
push_back 
offerLast 
push 
array_push 
append 
push 
push 
insert element at front 
push, cons 
Prepend 
push_front 
offerFirst 
unshift 
array_unshift 
appendleft 
unshift 
unshift 
remove last element 
eject 
Delete_Last 
pop_back 
pollLast 
pop 
array_pop 
pop 
pop 
pop 
remove first element 
pop 
Delete_First 
pop_front 
pollFirst 
shift 
array_shift 
popleft 
shift 
shift 
examine last element 
Last_Element 
back 
peekLast 
$array[- 1] 
end 
<obj>[-1] 
last 
<obj>[<obj>.length - 1] 
examine first element 
First_Element 
front 
peekFirst 
$array[0] 
reset 
<obj>[0] 
first 
<obj>[0] 
zegt wie? 
http://en.wikipedia.org/wiki/Double-ended_queue#Operations
lijsten 
3 
6 
-1 
7 
6 
ADT stack last-in-first-out 
top 
•create 
•is empty 
•insert ‘push’ 
•delete ‘pop’ 
•value at ‘top’ (?) when empty 
data types 
•element 
•position 
•list 
•boolean 
Drozdek 4.1
lijsten 
3 
6 
-1 
7 
6 
ADT queue first-in-first-out 
last 
back/tail 
•create 
•is empty 
•insert ‘enqueue’ 
•delete ‘dequeue’ 
•value at front (*) (?) when empty 
data types 
•element 
•position 
•list 
•boolean 
first 
front/head 
(*) andere kant makkelijk te implementeren 
Drozdek 4.2
representaties lijst 
representatie/implementatie lege lijst kopiëren, gelijkheidstest ‘diepte’ 
•array (bv:stack) willekeurige positie langzaam flexibele grootte: vector 
•linked enkel(queue) /dubbel verbonden 
prev 
next 
Λ 
last 
first
representaties lijst 
representatie/implementatie 
•array deque circular 
last 
first 
last 
first 
enqueue 
leeg / vol 
Drozdek 3.3
representaties lijst 
simplist: linkinversie 
vorig 
deze 
vorig 
deze 
slechts één positie ‘binnen lijst’ 
niet bij Drozdek
lijsten 
lijsten linear lists ADT vs. implementatie 
•list 
•double ended queue “deque” 
•stapel stack LIFO 
•rij queue FIFO 
gaan uit van 
elementen zonder ‘eigenschappen’ 
lineaire structuur vergelijk nu met 
set 
priority queue
set 
set [=verzameling] 
•als ADT, operaties? 
•implementatie? zoeken?

More Related Content

What's hot

Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJason Swartz
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesDebasish Ghosh
 
Link list part 2
Link list part 2Link list part 2
Link list part 2Anaya Zafar
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systemsleague
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In SwiftVadym Markov
 
Blank Row Find and Select
Blank Row Find and SelectBlank Row Find and Select
Blank Row Find and SelectRobert Burns
 
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...DmitryChirkin1
 
Julia meetup bangalore
Julia meetup bangaloreJulia meetup bangalore
Julia meetup bangaloreKrishna Kalyan
 

What's hot (15)

Collection Core Concept
Collection Core ConceptCollection Core Concept
Collection Core Concept
 
Java 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason SwartzJava 8 - An Introduction by Jason Swartz
Java 8 - An Introduction by Jason Swartz
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Namespace and methods
Namespace and methodsNamespace and methods
Namespace and methods
 
Clojure Linters
Clojure LintersClojure Linters
Clojure Linters
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In Swift
 
Python in 90 minutes
Python in 90 minutesPython in 90 minutes
Python in 90 minutes
 
Blank Row Find and Select
Blank Row Find and SelectBlank Row Find and Select
Blank Row Find and Select
 
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...
NodeUkraine - Postgresql для хипстеров или почему ваш следующий проект должен...
 
Stack queue
Stack queueStack queue
Stack queue
 
Julia meetup bangalore
Julia meetup bangaloreJulia meetup bangalore
Julia meetup bangalore
 

Similar to Datastruct2

Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Kenji HASUNUMA
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Kenji HASUNUMA
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreWeb Zhao
 
Data Structures and Files
Data Structures and FilesData Structures and Files
Data Structures and FilesKanchanPatil34
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonLifna C.S
 
Ch03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptCh03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptOliverKane3
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from javaIndicThreads
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CAlexis Gallagher
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 

Similar to Datastruct2 (20)

9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
 
Data structures
Data structuresData structures
Data structures
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Python3
Python3Python3
Python3
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
 
Data Structures and Files
Data Structures and FilesData Structures and Files
Data Structures and Files
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Ch03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptCh03_stacks_and_queues.ppt
Ch03_stacks_and_queues.ppt
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Queue
QueueQueue
Queue
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 

More from roy-de-zomer

More from roy-de-zomer (11)

Fis 12languages
Fis 12languagesFis 12languages
Fis 12languages
 
Fis 10binary
Fis 10binaryFis 10binary
Fis 10binary
 
Fis 05dragonl
Fis 05dragonlFis 05dragonl
Fis 05dragonl
 
Fis 04recursion
Fis 04recursionFis 04recursion
Fis 04recursion
 
Fis 03functions
Fis 03functionsFis 03functions
Fis 03functions
 
Fis 02relations
Fis 02relationsFis 02relations
Fis 02relations
 
Fis 01sets
Fis 01setsFis 01sets
Fis 01sets
 
Ds intro
Ds introDs intro
Ds intro
 
eg Datastruc4
eg Datastruc4eg Datastruc4
eg Datastruc4
 
Datastruct3
Datastruct3Datastruct3
Datastruct3
 
Datastruct1
Datastruct1Datastruct1
Datastruct1
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Datastruct2

  • 1. STL
  • 2. Standard Template Library • Standard Template Library template standard • container ‘sequentieel’ ‘associatief’ empty() size() • iterator vgl. pointer *p p++ == • algoritme zoeken, tellen kopiëren, reverse sorteren heap 31 77 67 35 02 - c.begin() c.end()
  • 3. STL container sequential vector array, dynamisch list lijst, dubbel verbonden deque array, tweezijdige associative set verzameling map sleutel+waarde paren multimap .. meerwaardig adaptor priority_queue (niet list) queue rij (niet vector) stack stapel
  • 4. STL vector #include <vector> int main() { vector<int> v; int i; for (i=0; i<10; i++) v.push_back(i); cout << v.size() << endl; for (i=0; i<10; i++) cout << v[i] << “ ”; cout << endl << v.front() << “ ” << v.back() << endl; vector<int>::iterator p = v.begin(); while ( p != v.end() ) { cout << *p << “ ”; p++; } return 0; }
  • 5. STL adaptor, map #include <vector> #include <stack> int main() { stack<vector<int> > st; int i; for (i=0; i<10; i++) st.push(i); while ( !st.isempty() ) { cout << st.top() << “ ”; st.pop(); } return 0; } #include <map> #include <string> int main() { map<string,int> mp; mp[“tim”] = 3; cout << mp[“tim”] << “ ” << mp[“bob”]; return 0; } map<string,int>::iterator p = mp.find(“bob”); spatie
  • 7. abstract data type ADT test in out
  • 8. lijsten 3 6 -1 7 6 lijsten linear lists ADT vs. implementatie •list •double ended queue “deque” •stapel stack LIFO •rij queue FIFO data type elementen hier niet belangrijk (bij sommige adt’s wél)
  • 9. lijsten 3 6 -1 7 6 ADT linear list first front/head last back/tail position •create •is empty •insert at/from front, back, position (?) before/after •delete at … (?) new position •value at position •search value return position (?) not found ‘abstract’ data elementen lijst data types •element •position •list •boolean
  • 10. lijsten 3 6 -1 7 6 ADT double ended queue first front/head last back/tail position •create •is empty •insert •delete •value at front, back (?) when empty ‘abstract’ data elementen lijst data types •element •position •list •boolean
  • 11. lijsten ADT double ended queue operation common name(s) Ada C++ Java Perl PHP Python Ruby Javascript insert element at back inject, snoc Append push_back offerLast push array_push append push push insert element at front push, cons Prepend push_front offerFirst unshift array_unshift appendleft unshift unshift remove last element eject Delete_Last pop_back pollLast pop array_pop pop pop pop remove first element pop Delete_First pop_front pollFirst shift array_shift popleft shift shift examine last element Last_Element back peekLast $array[- 1] end <obj>[-1] last <obj>[<obj>.length - 1] examine first element First_Element front peekFirst $array[0] reset <obj>[0] first <obj>[0] zegt wie? http://en.wikipedia.org/wiki/Double-ended_queue#Operations
  • 12. lijsten 3 6 -1 7 6 ADT stack last-in-first-out top •create •is empty •insert ‘push’ •delete ‘pop’ •value at ‘top’ (?) when empty data types •element •position •list •boolean Drozdek 4.1
  • 13. lijsten 3 6 -1 7 6 ADT queue first-in-first-out last back/tail •create •is empty •insert ‘enqueue’ •delete ‘dequeue’ •value at front (*) (?) when empty data types •element •position •list •boolean first front/head (*) andere kant makkelijk te implementeren Drozdek 4.2
  • 14. representaties lijst representatie/implementatie lege lijst kopiëren, gelijkheidstest ‘diepte’ •array (bv:stack) willekeurige positie langzaam flexibele grootte: vector •linked enkel(queue) /dubbel verbonden prev next Λ last first
  • 15. representaties lijst representatie/implementatie •array deque circular last first last first enqueue leeg / vol Drozdek 3.3
  • 16. representaties lijst simplist: linkinversie vorig deze vorig deze slechts één positie ‘binnen lijst’ niet bij Drozdek
  • 17. lijsten lijsten linear lists ADT vs. implementatie •list •double ended queue “deque” •stapel stack LIFO •rij queue FIFO gaan uit van elementen zonder ‘eigenschappen’ lineaire structuur vergelijk nu met set priority queue
  • 18. set set [=verzameling] •als ADT, operaties? •implementatie? zoeken?