SlideShare a Scribd company logo
Datastructuren Werkcollege Intro 
Bart Hijmans, Universiteit Leiden. 
Universiteit Leiden 
The Netherlands 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Focus 1 | 11 
ˆ Ervaring in gebruik en implementatie van datastructuren 
ˆ Kennis van mogelijkheden 
ˆ Programmeren voor andere programmeurs 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Uit Eerdere Colleges 2 | 11 
ˆ Korte, herbruikbare en leesbare functies 
Leiden University. The university to discover. 
ˆ Eciënte code 
ˆ Consequent inspringen 
ˆ Consequente naamgeving voor variabelen 
ˆ Gebruik geen Nederlands en Engels door elkaar 
ˆ Overweeg bijvoorbeeld camel case: maakNaamVoorFunctie() 
ˆ of lage streepjes: maak_naam_voor_functie()
Datastructuren Werkcollege Intro 
Files 3 | 11 
ˆ Iedere klasse een eigen header (.h) met klassedenitie 
ˆ Een andere programmeur ziet alleen de .h! 
ˆ Iedere klasse een eigen source (.cc of .cpp) met uitwerking 
ˆ Uitzondering: bij overerving mag de uitwerking in de .h 
ˆ Voor header les, gebruik preprocessor operaties om dubbele 
denities te voorkomen: 
#ifndef Bestandsnaam.h 
#define Bestandsnaam.h 
// normale code hier 
#endif 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Abstractie 4 | 11 
ˆ private, public en protected functies en variabelen 
ˆ Public: alleen functies die voor de gebruiker bedoeld zijn 
ˆ Private: alle variabelen (gebruik public get en set functies) 
ˆ Private: interne hulpfuncties 
ˆ Protected is vergelijkbaar met private, maar ook toegankelijk 
vanuit afgeleide klasses door inheritence. 
ˆ Zorg dat een gebruiker een datastructuur niet kapot kan 
maken 
ˆ Beschermt data en programmeurs 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Const Correctness 5 | 11 
ˆ Laat de programmeur weten welke functies niks veranderen 
aan de datastructuur en welke parameters zeker niet worden 
aangepast. 
ˆ const voor een parameter betekent dat dat parameter niet 
wordt aangepast 
ˆ const aan het eind van een functiedeclaratie betekent dat de 
datastructuur niet wordt aangepast 
bool zetInLijst(const int waarde); 
bool haalUitLijst(const int plaats, int waarde); 
bool isInLijst(const int waarde) const; 
ˆ static functies kunnen niet const zijn 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Const Correctness (2) 6 | 11 
ˆ Let op de verschillen tussen: 
ˆ int const * p; // p is pointer to const int 
ˆ int * const p; // p is const pointer to int 
ˆ int const * const p;//p is const pointer to const int 
ˆ Lees van rechts naar links 
ˆ Het is niet in alle gevallen mogelijk alles te verbieden, zorg 
wel dat je je er aan houdt! 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Commentaar Boven Files 7 | 11 
/** 
* klassenaam: beschrijving van klasse/programma 
* @author naam (studentnummer) 
* @author naam (studentnummer) 
* @file filenaam 
* @date datum laatste wijziging 
**/ 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Commentaar Boven Functies 8 | 11 
ˆ Boven (member)functiedeclaraties 
class dinges{ 
public: 
// commentaar hier! 
void doeIets(); 
} 
// Niet hier! 
void dinges::doeIets(){ 
} 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Commentaar Boven Functies (2) 9 | 11 
/** 
* @function functienaam 
* @abstract beschrijving wat de functie doet 
* @param parameternaam beschrijving rol parameter 
* @return beschrijving van het resultaat 
* @pre exacte beschrijving preconditie 
* @post exacte beschrijving postconditie 
**/ 
ˆ precondities moeten testbaar zijn! 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Uitzonderlijke Gevallen 10 | 11 
ˆ Wat gebeurt er als: 
ˆ een datastructuur vol is? 
ˆ een datastructuur leeg is? 
ˆ er een lege string wordt meegegeven? 
ˆ er een nullpointer wordt meegegeven? 
ˆ Let op dat postcondities alle gevallen beslaan 
ˆ Stel eisen aan parameters waar nodig 
ˆ Return booleans als een operatie kan falen! 
ˆ Gebruik nooit cout (of cerr) in een memberfunctie voor 
errors 
Leiden University. The university to discover.
Datastructuren Werkcollege Intro 
Standard Template Library datastructuren 11 | 11 
ˆ Bevat veel standaard datastructuren, waaronder vectors, 
lists, stacks, maps, queues en deques 
ˆ de interne werking is bijna altijd onbelangrijk. 
ˆ toegevoegd als include, bv #include stack 
ˆ Datastructuren zijn templates, ze werken voor elk type data, 
maar voor maar 1 tegelijk 
ˆ stackstring myStack; //een stack met strings 
ˆ listint myList; //een list met ints 
Leiden University. The university to discover.

More Related Content

Viewers also liked

Vre in onderwijs
Vre in onderwijsVre in onderwijs
Vre in onderwijsICTOLEIDEN
 
Trends college 2 - Het Scenario-Stappenplan
Trends   college 2 - Het Scenario-StappenplanTrends   college 2 - Het Scenario-Stappenplan
Trends college 2 - Het Scenario-Stappenplan
AeronAdvies
 
Trends college 6 - issue management, publieke opinie managen
Trends   college 6 - issue management, publieke opinie managenTrends   college 6 - issue management, publieke opinie managen
Trends college 6 - issue management, publieke opinie managen
AeronAdvies
 
Trends, College 1 - Intro in trendwatching
Trends, College 1 - Intro in trendwatchingTrends, College 1 - Intro in trendwatching
Trends, College 1 - Intro in trendwatching
AeronAdvies
 
Total branding
Total brandingTotal branding
Total branding
Bert Rorije
 
Beelden RK Parochie Joure (1912-2012)
Beelden RK Parochie Joure (1912-2012)Beelden RK Parochie Joure (1912-2012)
Beelden RK Parochie Joure (1912-2012)
Archief RK Friesland te Bolsward
 
Asia Trend Briefing - ASIA DATA DOMINANCE
Asia Trend Briefing - ASIA DATA DOMINANCEAsia Trend Briefing - ASIA DATA DOMINANCE
Asia Trend Briefing - ASIA DATA DOMINANCE
TrendWatching
 
Africa Trend Briefing - THE FUTURE OF AFRICONNECTION
Africa Trend Briefing - THE FUTURE OF AFRICONNECTIONAfrica Trend Briefing - THE FUTURE OF AFRICONNECTION
Africa Trend Briefing - THE FUTURE OF AFRICONNECTION
TrendWatching
 
POST-DEMOGRAPHIC IMPERATIVES
POST-DEMOGRAPHIC IMPERATIVESPOST-DEMOGRAPHIC IMPERATIVES
POST-DEMOGRAPHIC IMPERATIVES
TrendWatching
 
Global Trend Briefing - BIG BRAND REDEMPTION
Global Trend Briefing - BIG BRAND REDEMPTIONGlobal Trend Briefing - BIG BRAND REDEMPTION
Global Trend Briefing - BIG BRAND REDEMPTION
TrendWatching
 
9 WAYS TO BUILD A TREND CULTURE
9 WAYS TO BUILD A TREND CULTURE9 WAYS TO BUILD A TREND CULTURE
9 WAYS TO BUILD A TREND CULTURE
TrendWatching
 
AUTONOMANIA: Chatbots, AI, self-driving cars and more!
AUTONOMANIA: Chatbots, AI, self-driving cars and more!AUTONOMANIA: Chatbots, AI, self-driving cars and more!
AUTONOMANIA: Chatbots, AI, self-driving cars and more!
TrendWatching
 
THE FUTURE OF LUXURY - Global Trend Briefing
THE FUTURE OF LUXURY - Global Trend BriefingTHE FUTURE OF LUXURY - Global Trend Briefing
THE FUTURE OF LUXURY - Global Trend Briefing
TrendWatching
 

Viewers also liked (13)

Vre in onderwijs
Vre in onderwijsVre in onderwijs
Vre in onderwijs
 
Trends college 2 - Het Scenario-Stappenplan
Trends   college 2 - Het Scenario-StappenplanTrends   college 2 - Het Scenario-Stappenplan
Trends college 2 - Het Scenario-Stappenplan
 
Trends college 6 - issue management, publieke opinie managen
Trends   college 6 - issue management, publieke opinie managenTrends   college 6 - issue management, publieke opinie managen
Trends college 6 - issue management, publieke opinie managen
 
Trends, College 1 - Intro in trendwatching
Trends, College 1 - Intro in trendwatchingTrends, College 1 - Intro in trendwatching
Trends, College 1 - Intro in trendwatching
 
Total branding
Total brandingTotal branding
Total branding
 
Beelden RK Parochie Joure (1912-2012)
Beelden RK Parochie Joure (1912-2012)Beelden RK Parochie Joure (1912-2012)
Beelden RK Parochie Joure (1912-2012)
 
Asia Trend Briefing - ASIA DATA DOMINANCE
Asia Trend Briefing - ASIA DATA DOMINANCEAsia Trend Briefing - ASIA DATA DOMINANCE
Asia Trend Briefing - ASIA DATA DOMINANCE
 
Africa Trend Briefing - THE FUTURE OF AFRICONNECTION
Africa Trend Briefing - THE FUTURE OF AFRICONNECTIONAfrica Trend Briefing - THE FUTURE OF AFRICONNECTION
Africa Trend Briefing - THE FUTURE OF AFRICONNECTION
 
POST-DEMOGRAPHIC IMPERATIVES
POST-DEMOGRAPHIC IMPERATIVESPOST-DEMOGRAPHIC IMPERATIVES
POST-DEMOGRAPHIC IMPERATIVES
 
Global Trend Briefing - BIG BRAND REDEMPTION
Global Trend Briefing - BIG BRAND REDEMPTIONGlobal Trend Briefing - BIG BRAND REDEMPTION
Global Trend Briefing - BIG BRAND REDEMPTION
 
9 WAYS TO BUILD A TREND CULTURE
9 WAYS TO BUILD A TREND CULTURE9 WAYS TO BUILD A TREND CULTURE
9 WAYS TO BUILD A TREND CULTURE
 
AUTONOMANIA: Chatbots, AI, self-driving cars and more!
AUTONOMANIA: Chatbots, AI, self-driving cars and more!AUTONOMANIA: Chatbots, AI, self-driving cars and more!
AUTONOMANIA: Chatbots, AI, self-driving cars and more!
 
THE FUTURE OF LUXURY - Global Trend Briefing
THE FUTURE OF LUXURY - Global Trend BriefingTHE FUTURE OF LUXURY - Global Trend Briefing
THE FUTURE OF LUXURY - Global Trend Briefing
 

Similar to Ds intro

Edit a-thon invulboek objecten op cest
Edit a-thon invulboek objecten op cestEdit a-thon invulboek objecten op cest
Edit a-thon invulboek objecten op cest
PACKED vzw
 
Edit-a-thon invulboek objecten op cest
Edit-a-thon invulboek objecten op cestEdit-a-thon invulboek objecten op cest
Edit-a-thon invulboek objecten op cest
meemoo, Vlaams instituut voor het archief
 
Presentatie design principles
Presentatie design principlesPresentatie design principles
Presentatie design principles
Ernst Bunders
 
Profiel thymos rudi respen
Profiel thymos   rudi respenProfiel thymos   rudi respen
Profiel thymos rudi respen
Rudi Respen
 
Clean, effective java
Clean, effective javaClean, effective java
Clean, effective java
Bert Van Vreckem
 

Similar to Ds intro (6)

Programmeer techniek
Programmeer techniekProgrammeer techniek
Programmeer techniek
 
Edit a-thon invulboek objecten op cest
Edit a-thon invulboek objecten op cestEdit a-thon invulboek objecten op cest
Edit a-thon invulboek objecten op cest
 
Edit-a-thon invulboek objecten op cest
Edit-a-thon invulboek objecten op cestEdit-a-thon invulboek objecten op cest
Edit-a-thon invulboek objecten op cest
 
Presentatie design principles
Presentatie design principlesPresentatie design principles
Presentatie design principles
 
Profiel thymos rudi respen
Profiel thymos   rudi respenProfiel thymos   rudi respen
Profiel thymos rudi respen
 
Clean, effective java
Clean, effective javaClean, effective java
Clean, effective java
 

More from roy-de-zomer

Fis 12languages
Fis 12languagesFis 12languages
Fis 12languages
roy-de-zomer
 
Fis 10binary
Fis 10binaryFis 10binary
Fis 10binary
roy-de-zomer
 
Fis 05dragonl
Fis 05dragonlFis 05dragonl
Fis 05dragonl
roy-de-zomer
 
Fis 04recursion
Fis 04recursionFis 04recursion
Fis 04recursion
roy-de-zomer
 
Fis 03functions
Fis 03functionsFis 03functions
Fis 03functions
roy-de-zomer
 
Fis 02relations
Fis 02relationsFis 02relations
Fis 02relations
roy-de-zomer
 
Fis 01sets
Fis 01setsFis 01sets
Fis 01sets
roy-de-zomer
 
eg Datastruc4
eg Datastruc4eg Datastruc4
eg Datastruc4
roy-de-zomer
 
Datastruct3
Datastruct3Datastruct3
Datastruct3
roy-de-zomer
 
Datastruct2
Datastruct2Datastruct2
Datastruct2
roy-de-zomer
 
Datastruct1
Datastruct1Datastruct1
Datastruct1
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
 
eg Datastruc4
eg Datastruc4eg Datastruc4
eg Datastruc4
 
Datastruct3
Datastruct3Datastruct3
Datastruct3
 
Datastruct2
Datastruct2Datastruct2
Datastruct2
 
Datastruct1
Datastruct1Datastruct1
Datastruct1
 

Ds intro

  • 1. Datastructuren Werkcollege Intro Bart Hijmans, Universiteit Leiden. Universiteit Leiden The Netherlands Leiden University. The university to discover.
  • 2. Datastructuren Werkcollege Intro Focus 1 | 11 ˆ Ervaring in gebruik en implementatie van datastructuren ˆ Kennis van mogelijkheden ˆ Programmeren voor andere programmeurs Leiden University. The university to discover.
  • 3. Datastructuren Werkcollege Intro Uit Eerdere Colleges 2 | 11 ˆ Korte, herbruikbare en leesbare functies Leiden University. The university to discover. ˆ Eciënte code ˆ Consequent inspringen ˆ Consequente naamgeving voor variabelen ˆ Gebruik geen Nederlands en Engels door elkaar ˆ Overweeg bijvoorbeeld camel case: maakNaamVoorFunctie() ˆ of lage streepjes: maak_naam_voor_functie()
  • 4. Datastructuren Werkcollege Intro Files 3 | 11 ˆ Iedere klasse een eigen header (.h) met klassedenitie ˆ Een andere programmeur ziet alleen de .h! ˆ Iedere klasse een eigen source (.cc of .cpp) met uitwerking ˆ Uitzondering: bij overerving mag de uitwerking in de .h ˆ Voor header les, gebruik preprocessor operaties om dubbele denities te voorkomen: #ifndef Bestandsnaam.h #define Bestandsnaam.h // normale code hier #endif Leiden University. The university to discover.
  • 5. Datastructuren Werkcollege Intro Abstractie 4 | 11 ˆ private, public en protected functies en variabelen ˆ Public: alleen functies die voor de gebruiker bedoeld zijn ˆ Private: alle variabelen (gebruik public get en set functies) ˆ Private: interne hulpfuncties ˆ Protected is vergelijkbaar met private, maar ook toegankelijk vanuit afgeleide klasses door inheritence. ˆ Zorg dat een gebruiker een datastructuur niet kapot kan maken ˆ Beschermt data en programmeurs Leiden University. The university to discover.
  • 6. Datastructuren Werkcollege Intro Const Correctness 5 | 11 ˆ Laat de programmeur weten welke functies niks veranderen aan de datastructuur en welke parameters zeker niet worden aangepast. ˆ const voor een parameter betekent dat dat parameter niet wordt aangepast ˆ const aan het eind van een functiedeclaratie betekent dat de datastructuur niet wordt aangepast bool zetInLijst(const int waarde); bool haalUitLijst(const int plaats, int waarde); bool isInLijst(const int waarde) const; ˆ static functies kunnen niet const zijn Leiden University. The university to discover.
  • 7. Datastructuren Werkcollege Intro Const Correctness (2) 6 | 11 ˆ Let op de verschillen tussen: ˆ int const * p; // p is pointer to const int ˆ int * const p; // p is const pointer to int ˆ int const * const p;//p is const pointer to const int ˆ Lees van rechts naar links ˆ Het is niet in alle gevallen mogelijk alles te verbieden, zorg wel dat je je er aan houdt! Leiden University. The university to discover.
  • 8. Datastructuren Werkcollege Intro Commentaar Boven Files 7 | 11 /** * klassenaam: beschrijving van klasse/programma * @author naam (studentnummer) * @author naam (studentnummer) * @file filenaam * @date datum laatste wijziging **/ Leiden University. The university to discover.
  • 9. Datastructuren Werkcollege Intro Commentaar Boven Functies 8 | 11 ˆ Boven (member)functiedeclaraties class dinges{ public: // commentaar hier! void doeIets(); } // Niet hier! void dinges::doeIets(){ } Leiden University. The university to discover.
  • 10. Datastructuren Werkcollege Intro Commentaar Boven Functies (2) 9 | 11 /** * @function functienaam * @abstract beschrijving wat de functie doet * @param parameternaam beschrijving rol parameter * @return beschrijving van het resultaat * @pre exacte beschrijving preconditie * @post exacte beschrijving postconditie **/ ˆ precondities moeten testbaar zijn! Leiden University. The university to discover.
  • 11. Datastructuren Werkcollege Intro Uitzonderlijke Gevallen 10 | 11 ˆ Wat gebeurt er als: ˆ een datastructuur vol is? ˆ een datastructuur leeg is? ˆ er een lege string wordt meegegeven? ˆ er een nullpointer wordt meegegeven? ˆ Let op dat postcondities alle gevallen beslaan ˆ Stel eisen aan parameters waar nodig ˆ Return booleans als een operatie kan falen! ˆ Gebruik nooit cout (of cerr) in een memberfunctie voor errors Leiden University. The university to discover.
  • 12. Datastructuren Werkcollege Intro Standard Template Library datastructuren 11 | 11 ˆ Bevat veel standaard datastructuren, waaronder vectors, lists, stacks, maps, queues en deques ˆ de interne werking is bijna altijd onbelangrijk. ˆ toegevoegd als include, bv #include stack ˆ Datastructuren zijn templates, ze werken voor elk type data, maar voor maar 1 tegelijk ˆ stackstring myStack; //een stack met strings ˆ listint myList; //een list met ints Leiden University. The university to discover.