Lecture 8 - Using Sequential Containers

Lecture 8 - Using Sequential Containers -...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Using Sequential Containers Lecture 8 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/˜ hkaiser /fall_2011/csc1254.html  
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Principle of the Day Principle of least astonishment (POLA/PLA) The principle of least astonishment is usually  referenced in regards to the user interface, but the  same principle applies to written code.  Code should surprise the reader as little as  possible. That means following standard  conventions, code should do what the comments  and name suggest, and potentially surprising side  effects should be avoided as much as possible.  9/22/2 011,  Lecture  8 CSC 1254,  Fall 2011,  Using  Sequential  Containers 2
Background image of page 2
Abstract We start looking beyond vector and string. We  will focus on sequential containers and  demonstrate a couple of problems we can solve  when applying them. The standard library’s architecture will start to  get visible. That will help us to start  understanding how to use all of the different  containers in the standard library. 9/22/2 011,  Lecture  8 CSC 1254,  Fall 2011,  Using  Sequential  Containers 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Separating Students into  Categories Sort out failed students Who failed?  Remove from our data Create a new vector of  student_data   containing only students who succeeded: // predicate to determine whether a student failed bool fail_grade(student_info const { return grade(s) < 60; 9/22/2 011,  Lecture  8 CSC 1254,  Fall 2011,  Using  Sequential  Containers 4
Background image of page 4
Separating Students into  Categories What’s wrong here? (Hint: what’s the memory  consumption?) // separate passing and failing student records: first try vector<student_info> { vector<student_info> pass, fail; for (vector<student_info>::size_type i = 0; i != students.size(); ++i) 9/22/2 011,  Lecture  8 CSC 1254,  Fall 2011,  Using  Sequential  Containers 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Categories Requires twice as much memory Each record is held twice Better to copy failed students, removing the data  from original vector How to remove elements from a vector? Slow, too slow for larger amounts of data.  Why? What happens if all students have failed?
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2011 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 25

Lecture 8 - Using Sequential Containers -...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online