19_operators_priority_queues_intro

19_operators_priority_queues_intro - CSCI-1200 Computer...

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

View Full Document Right Arrow Icon
CSCI-1200 Computer Science II — Fall 2010 and Priority Queues, Part I Announcements: Test 3 Information Test 3 will be held on Tuesday, November 16th, 2010 from 2-3:50pm in West Hall Auditorium . No make-ups will be given except for emergency situations, and even then a written excuse from the Dean of Students office will be required. Coverage: Lectures 1-19, Labs 1-11, HW 1-8. Closed-book and closed-notes handwritten or printed . Review from Lecture 18 increment and decrement operations on iterators red-black trees Today’s Lecture Operators as non-member functions, as member functions, and as friend functions. Queues and Stacks, What’s a Priority Queue? A Priority Queue as a Heap, percolate_up and percolate_down 19.1 Complex Numbers — A Brief Review Complex numbers take the form z = a + bi , where i = - 1 and a and b are real. a is called the real part, b is called the imaginary part. If w = c + di , then w + z = ( a + c ) + ( b + d ) i , w - z = ( a - c ) + ( b - d ) i , and w × z = ( ac - bd ) + ( ad + bc ) i The magnitude of a complex number is a 2 + b 2 . 19.2 Complex Class declaration ( complex.h ) class Complex { public: Complex(double x=0, double y=0) : real_(x), imag_(y) {} // default constructor // copy constructor Complex& operator= (Complex const& rhs); // Assignment operator double Real() const { return real_; } void SetReal(double x) { real_ = x; } double Imaginary() const { return imag_; } void SetImaginary(double y) { imag_ = y; } double Magnitude() const { return sqrt(real_*real_ + imag_*imag_); } Complex operator+ (Complex const& rhs) const; Complex operator- () const; // unary operator- negates a complex number friend istream& operator>> (istream& istr, Complex& c); private: double real_, imag_; }; Complex operator- (Complex const& left, Complex const& right); // non-member function ostream& operator // non-member function
Background image of page 1

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

View Full DocumentRight Arrow Icon
19.3 Implementation of Complex Class ( complex.cpp ) // Assignment operator real_ = rhs.real_; imag_ = rhs.imag_; return *this; } // Addition operator as a member function. double re = real_ + rhs.real_; double im = imag_ + rhs.imag_; return Complex(re, im); } // Subtraction operator as a non-member function. return Complex(lhs.Real()-rhs.Real(), lhs.Imaginary()-rhs.Imaginary()); } // Unary negation operator. Note that there are no arguments.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2012 for the course CSCI 1200 taught by Professor Cutler during the Fall '08 term at Rensselaer Polytechnic Institute.

Page1 / 6

19_operators_priority_queues_intro - CSCI-1200 Computer...

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

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