Computer Science 1037A/B Lecture Notes - Lecture 7: Standard Template Library

50 views3 pages

Document Summary

Vectors hold a set of elements, like a one dimensional array. It is a flexible array of number elements, meaning it can grow and shrink. No need to specify size when defined, automatically adds more space as needed. Defined in the standard template library (stl), so you must include Can hold values of any type, and type is specified when a vector is defined. Stores its elements in contiguous memory locations, can use [] to access elements. Defining a vector of integers (starts with 0 elements: vector scores; Define int vector with initial size 30 elements: vector scores(30); Define 20 element int vector and initialize all elements to 0: vector scores(20,0); In this case, scores is an exact copy of finals: vector scores(finals); Use push_back(value) to add an element to a full vector or to a vector that had no defined size. Use size() member function to determine number of elements currently in a vector.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents