Skip to content

Instantly share code, notes, and snippets.

@odeblic
Created July 29, 2017 14:35
Show Gist options
  • Save odeblic/e5bab146fc809318b8207fd9be87e36b to your computer and use it in GitHub Desktop.
Save odeblic/e5bab146fc809318b8207fd9be87e36b to your computer and use it in GitHub Desktop.
To be tested...
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <unordered_set>
#include <algorithm>
using namespace std;
template<typename T>
void display(const T& container)
{
cout << ":";
for(auto i : container)
{
cout << " " << i;
}
cout << endl;
}
template<typename T>
void release(T& container)
{
cout << ":";
while(container.size() > 0)
{
cout << " " << container.top();
container.pop();
}
cout << endl;
}
int main()
{
set<int> xset {5, -2, 1, 9, -4, 0, 7, -3, 1, -2, 16, 4};
multiset<int> xmultiset {5, -2, 1, 9, -4, 0, 7, -3, 1, -2, 16, 4};
unordered_set<int> xunorderedset {5, -2, 1, 9, -4, 0, 7, -3, 1, -2, 16, 4};
unordered_multiset<int> xunorderedmultiset {5, -2, 1, 9, -4, 0, 7, -3, 1, -2, 16, 4};
display(xset);
display(xmultiset);
display(xunorderedset);
display(xunorderedmultiset);
return 0;
priority_queue<int> queue;
//queue<int> queue;
queue.push(2);
queue.push(4);
queue.push(6);
queue.push(8);
queue.push(3);
queue.emplace(11);
release(queue);
return 0;
vector<int> tab {5, 1, 9, -4, 0, 7, -3, -2, 16, 4};
display(tab);
auto min = min_element(tab.begin(), tab.end());
auto max = max_element(tab.begin(), tab.end());
cout << "min=" << *min << endl;
cout << "max=" << *max << endl;
auto zero = min + 1;
cout << "zero=" << *zero << endl;
auto min_left = min_element(tab.begin(), zero);
auto max_left = max_element(tab.begin(), zero);
auto min_right = min_element(zero, tab.end());
auto max_right = max_element(zero, tab.end());
cout << "min_left=" << *min_left << endl;
cout << "max_left=" << *max_left << endl;
cout << "min_right=" << *min_right << endl;
cout << "max_right=" << *max_right << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment