Skip to content

Instantly share code, notes, and snippets.

View liuguiyangnwpu's full-sized avatar
💭
I may be slow to respond.

GuiYang liuguiyangnwpu

💭
I may be slow to respond.
View GitHub Profile
@liuguiyangnwpu
liuguiyangnwpu / STL_Heap_Struct.md
Last active August 3, 2016 11:25
使用STL容器构造堆数据结构
  • 使用STL中的优先级队列进行堆数据结构的建立
priority_queue<Type, Container, Functional>
Type - 数据类型
Container - 保存数据的容器
Functional - 用来指定数据之间的比较规则

STL中的默认的priority_queue是存储类型为vector的大顶堆,使用方式如下
priority_queue<int, vector<int>, less<int>> high_heap;
@liuguiyangnwpu
liuguiyangnwpu / Learning STL 02.md
Created August 2, 2016 07:45
How to free the pointer which allocated on the heap, use different method !
  • when using containers of newed pointers, remember to delete the pointers before the container is destroyed.
void doSomething() {
	vector<Widget*> vwp;
	for(int i=0;i<NUMS;++i) {
		vwp.push_back(new Widget);
	}
}
// Widgets are leaked here !
@liuguiyangnwpu
liuguiyangnwpu / Learning STL 01.md
Last active August 2, 2016 07:10
How to write a class with STL
class Widget { ... };
vector<Widget> vw;
Widget bestWidget;
vector<Widget>::iterator it =find(vw.begin(), vw.end(), bestWidget);

you should write this