lecture9 notes

Lecture9 notes

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: << " " << arr[i]; cout << endl; } int main() { int a = {5, 7, 2, 1, 4, 3, 6}; sort(a, a+7); printArray(a, 7); rotate(a,a+3,a+7); printArray(a, 7); reverse(a, a+7); printArray(a, 7); return 0; } This program prints out: 1 2 3 4 5 6 7 4 5 6 7 1 2 3 3 2 1 7 6 5 4 The STL has many, many more containers and algorithms that you can use. Read more at http://www.cplusplus.com/reference/stl and http://www.cplusplus.com/reference/algorithm/. 3 Operator Overloading We have been using operators on primitives, but sometimes it makes sense to use them on user-defined datatypes. For instance, consider the following struct: struct USCurrency { int dollars; int cents; }; Perhaps we would like to add two USCurrency objects together and get a new one as a result, just like in normal addition: USCurrency a = {2, 50}; USCurrency b = {1, 75}; USCurrency c = a + b; This of course gives a compiler error, but we can define behavior that our datatype should have when used with...
View Full Document

This document was uploaded on 03/18/2014 for the course EECS 6.096 at MIT.

Ask a homework question - tutors are online