chapter4 - .

Info icon This preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 4 Sequential Containers
Image of page 1

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

View Full Document Right Arrow Icon
Chapter Objectives To become familiar with the Standard Template Library (STL) and template classes To understand how to use a vector class and how to implement it using an array for storage To understand the difference between a shallow copy and deep copy To introduce linked lists and study the differences between single-, double-, and circular linked list data structures To introduce structs
Image of page 2
Chapter Objectives (cont.) To understand the iterator To learn how to implement the STL list class To learn how to implement the iterator for a linked list To learn how to declare aliases and use delegation To become familiar with the STL sequential containers To introduce the functions in the algorithm header
Image of page 3

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

View Full Document Right Arrow Icon
Introduction So far we’ve considered one data structure that you can use in your programming—the array The C++ developers have provided more tools for programmers by providing a rich set of data structures written as C++ template classes These template classes are all part of the Standard Template Library (STL) In this chapter we discuss the STL classes called sequences
Image of page 4
Introduction (cont.) A sequence has the property that elements can be inserted or removed anywhere in the sequence, not just at the beginning or at the end Some sequences are indexed, which means their elements can be accessed in arbitrary order (called random access ) using a subscript to select an element For other sequences you must start at the beginning and process the elements in order
Image of page 5

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

View Full Document Right Arrow Icon
Introduction (cont.) In this chapter, we discuss iterators and their role in facilitating sequential access and random access discuss the vector and list (linked list) classes and their similarities and differences show that these classes implement the common interface requirements for sequential containers
Image of page 6
Section 4.1 Template Classes and the Vector
Image of page 7

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

View Full Document Right Arrow Icon
Template Classes and the Vector A template class is a class that stores and processes a collection of information template<typename T> class some_container { ... }
Image of page 8
Template Classes and the Vector (cont.) A template class is a class that stores and processes a collection of information template<typename T> class some_container { ... } In this code, some_container is declared to be a template class
Image of page 9

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

View Full Document Right Arrow Icon
Template Classes and the Vector (cont.) A template class is a class that stores and processes a collection of information template<typename T> class some_container { ... } The parameter T is a placeholder for the actual data type of the information to be stored in some_container
Image of page 10
Template Classes and the Vector (cont.) A template class is a class that stores and processes a collection of information template<typename T> class some_container { ... } some_container<int> call_lengths; some_container<Person> people;
Image of page 11

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

View Full Document Right Arrow Icon
Template Classes and the Vector (cont.) A template class is a class that stores and processes a collection of information template<typename T> class some_container { ... } some_container<int> call_lengths; some_container<Person> people; These two lines each create instances of some_container
Image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern