class Widget { ... };
vector<Widget> vw;
Widget bestWidget;
vector<Widget>::iterator it =find(vw.begin(), vw.end(), bestWidget);
you should write this
class Widget { ... };
vector<Widget> vw;
Widget bestWidget;
vector<Widget>::iterator it =find(vw.begin(), vw.end(), bestWidget);
you should write this
void doSomething() {
vector<Widget*> vwp;
for(int i=0;i<NUMS;++i) {
vwp.push_back(new Widget);
}
}
// Widgets are leaked here !
priority_queue<Type, Container, Functional>
Type - 数据类型
Container - 保存数据的容器
Functional - 用来指定数据之间的比较规则
STL中的默认的priority_queue是存储类型为vector的大顶堆,使用方式如下
priority_queue<int, vector<int>, less<int>> high_heap;
Internally, the elements in the unordered_map are not sorted in any particular order with respect to either their key or mapped values, but organized into buckets depending on their hash values to allow for fast access to individual elements directly by their key values (with a constant average time complexity on average).
unordered_map containers are faster than map containers to access individual elements by their key, although they are generally less efficient for range iteration through a subset of their elements.
这段英文按我的理解就是unordered_map的快速插入和快速查找都是没有问题的,只不过对于迭代器遍历的速度恐怕会相比低效一些。
对于一个单链表,我们假设这样一种情况,我们不知道单链表的头节点,我们只是知道单链表中某一个节点的指针,现在我们想删除这个节点,我们如何做到?
在我做leetcode是遇到这样的一个问题,设计一个数据结构,实现插入、删除、随机获取一个数据的均需要咋O(1)的时间完成。
class RandomizedSet {
public:
/** Initialize your data structure here. */
#include <iostream>
#include <vector>
using namespace std;
const int NodeMax = 26;
typedef struct _TrieNode {
int cnt;
struct _TrieNode* next[NodeMax];
#!/usr/bin/env python
# coding=utf-8
import os
import pandas as pd
saveDir = "/home/fighter/imageretrievedata/for_train/"
def deal_cluster(filePaths):