标签:sign ora code 编程 col color vector 创建 存储
void main() { int array[] = { 1, 2, 3, 4, 5 }; std::vector<int> v; v.reserve(5); v.assign(array, array + 5); typedef std::vector<int>::iterator iterator; iterator p = v.begin(); iterator q = v.end() - 1; v.erase(p + 1, p + 3); v.insert(v.end(), array, array + 5); getchar(); }
std::stack<int, std::vector<int>> vector_stack; //用vector实现stack std::stack<int> deque_stack; //用deque实现stack std::queue<char, std::list<char>> queue; //用list实现queue std::queue<char> deque_queue; //用deque实现queue
#include <iostream> #include <queue> #include <vector> struct my_pair { int first; int second; }; struct comp_my_pair//这是一个函数对象 { bool operator()(my_pair const &left, my_pair const &right) { return left.first == right.first ? left.second > right.second : left.first > right.first; } }; void main() { my_pair array[] = {{3, 0}, {2, 1}, {1, 2}, {0, 3}, {0, 4}}; using std::priority_queue; using std::vector; priority_queue<my_pair, vector<my_pair>, comp_my_pair> pq(array, array + 5); while(!pq.empty()) { std::cout << pq.top().first << ", " << pq.top().second << std::endl; pq.pop(); } return; }
typedef std::set<int> int_set; typedef void func_type(int*, int*); float measure(func_type func, int *start, int *end) { //int start_clock = clock(); func(start, end); //int end_clock = clock(); return 0; //return float(end_clock - start_clock) / CLOCKS_PER_SEC; } void test_plain_insert(int *start, int *end) { int_set s; s.insert(start, end); for(int_set::iterator it = s.begin(); it != s.end(); it++) { printf("%d ", *it); } printf("\n"); } void test_smart_insert(int *start, int *end) { int_set s; int_set::iterator prev = s.begin(); for(; start != end; ++start) { prev = s.insert(prev, *start); for(int_set::iterator it = s.begin(); it != s.end(); it++) { printf("prev:%d ;", *prev); printf("%d ", *it); } printf("\n"); } printf("\n"); } void main() { const int num = 8; const int half = num / 2; int array1[num]; int array2[num]; for(int i = 0; i < num; ++i) { array1[i] = i; array2[i] = (i & 1) ? (i - num) : (num - i); } measure(test_plain_insert, array2, array2 + num -1); measure(test_smart_insert, array2, array2 + num -1); //measure(test_plain_insert, array1, array1 + num -1); //measure(test_smart_insert, array1, array1 + num -1); return; }
标签:sign ora code 编程 col color vector 创建 存储
原文地址:https://www.cnblogs.com/predator-wang/p/11518372.html