85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
|
|
#include "Pixel.h"
|
|
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
void pixelPrint(const Pixel &pixel) { pixel.print(); }
|
|
|
|
void pixelPtrPrint(const Pixel *pixel) { pixel->print(); }
|
|
|
|
int main() {
|
|
using namespace std;
|
|
|
|
// preamble
|
|
Pixel pixel0;
|
|
cout << "Preamble:" << endl;
|
|
pixel0.print();
|
|
cout << endl;
|
|
|
|
Pixel pixel1(1, 2);
|
|
Pixel pixel2(3, 3);
|
|
Pixel pixel3(2, 4);
|
|
Pixel pixel4(5, 2);
|
|
Pixel pixel5(4, 2);
|
|
|
|
// 3.1 part 1
|
|
cout << "3.1 Part 1:" << endl;
|
|
vector<Pixel> pixelVec;
|
|
pixelVec.push_back(pixel1);
|
|
pixelVec.push_back(pixel2);
|
|
pixelVec.push_back(pixel3);
|
|
pixelVec.push_back(pixel4);
|
|
pixelVec.push_back(pixel5);
|
|
|
|
for (unsigned int i = 0; i < pixelVec.size(); ++i) {
|
|
pixelVec[i].print();
|
|
}
|
|
cout << endl;
|
|
|
|
// 3.1 part 2
|
|
cout << "3.1 Part 2:" << endl;
|
|
for (vector<Pixel>::iterator iter = pixelVec.begin(); iter != pixelVec.end(); ++iter) {
|
|
iter->print();
|
|
}
|
|
cout << endl;
|
|
for (vector<Pixel>::reverse_iterator r_iter = pixelVec.rbegin(); r_iter != pixelVec.rend(); ++r_iter) {
|
|
r_iter->print();
|
|
}
|
|
cout << endl;
|
|
|
|
// 3.1 part 3
|
|
cout << "3.1 Part 3:" << endl;
|
|
for_each(pixelVec.begin(), pixelVec.end(), pixelPrint);
|
|
cout << endl;
|
|
sort(pixelVec.begin(), pixelVec.end());
|
|
for_each(pixelVec.begin(), pixelVec.end(), pixelPrint);
|
|
cout << endl;
|
|
|
|
// 3.2
|
|
cout << "3.2, Part 1:" << endl;
|
|
vector<Pixel *> pixelPtrVec;
|
|
pixelPtrVec.push_back(&pixel1);
|
|
pixelPtrVec.push_back(&pixel2);
|
|
pixelPtrVec.push_back(&pixel3);
|
|
pixelPtrVec.push_back(&pixel4);
|
|
pixelPtrVec.push_back(&pixel5);
|
|
|
|
for_each(pixelPtrVec.begin(), pixelPtrVec.end(), pixelPtrPrint);
|
|
cout << endl;
|
|
PixelPtrCompare pixelPtrComp;
|
|
sort(pixelPtrVec.begin(), pixelPtrVec.end(), pixelPtrComp);
|
|
for_each(pixelPtrVec.begin(), pixelPtrVec.end(), pixelPtrPrint);
|
|
cout << endl;
|
|
pixelPtrComp.setSortOnY(true);
|
|
sort(pixelPtrVec.begin(), pixelPtrVec.end(), pixelPtrComp);
|
|
for_each(pixelPtrVec.begin(), pixelPtrVec.end(), pixelPtrPrint);
|
|
cout << endl;
|
|
|
|
cout << endl;
|
|
|
|
// insert code here...
|
|
|
|
return 0;
|
|
} |