Created
February 16, 2009 10:41
-
-
Save farcaller/65110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
#include <stdlib.h> | |
#define SIZE 3 | |
class Comparator | |
{ | |
private: | |
int items[SIZE]; | |
public: | |
Comparator(int *i) { memcpy(&items, i, sizeof(items)); }; | |
int min(); | |
int max(); | |
}; | |
int Comparator::min() | |
{ | |
return *std::min_element(items, items + sizeof(items) / sizeof(items[0])); | |
} | |
int Comparator::max() | |
{ | |
return *std::max_element(items, items + sizeof(items) / sizeof(items[0])); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if(argc != 4) | |
return 2; | |
int itms[SIZE]; | |
for(int i=0; i<SIZE; ++i) { | |
itms[i] = strtol(argv[i+1], NULL, 10); | |
} | |
Comparator cmp(itms); | |
std::cout << "Min value: " << cmp.min() << std::endl | |
<< "Max value: " << cmp.max() << std::endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment