본문 바로가기

2018-02/c++

(25)
STL Stack 한가지 특이한 점은 top을 써야되고 pop은 void return이라는 점 123456789101112131415#include using namespace std; int main() { stack tmp; tmp.push(3); tmp.push(4); cout
IO 123456789101112#include using namespace std; int main() { double s = 0.123456789; cout
File I/O #include 1234567891011121314151617181920212223int main() { ofstream out("out.out"); for (int i = 0; i
STL Queues queue나 priority queue는 둘다 iterator가 없다.priority queue는 max heap / min heap 사용 가능. 12345678910111213141516171819202122232425262728293031323334353637383940414243#include "stdafx.h"#include #include #include #include #include #include #include using namespace std; int main() { priority_queue tmp; tmp.push(pair(1, 4)); tmp.push(pair(1, 3)); tmp.push(pair(1, 2)); tmp.push(pair(1, 1)); tmp.push(pair(2..
SORTING 1234567891011121314151617bool comparator(int a, int b){ return a>b;} int main(){ vector v = {5,1,4,8,7,4,9,2}; sort(v.begin(),v.end(),comparator); for(int i : v){ cout
maps STL 123456789101112131415161718192021222324int main() { unordered_multimap yeah; multimap test3; // test3[1] = 2; 불가능 //test3.insert(pair(1, 2)); test3.insert(pair(1, 3)); test3.insert(pair(1, 4)); test3.insert(pair(1, 5)); test3.insert(pair(1, 2)); cout
variables and memory, declaration 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include "stdafx.h"#include #include #include using namespace std; class sam {public: int a; int b; sam(int z, int w) { a = z; b = w; }}; int main2() { sam * test = new sam(1, 2); return 0;} struct node { int data; node * next;}; void append(int data, node * head) { node * hel..
list inserts and deletes 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859void splitx(list &data, int x) { list::iterator low, high, it, tmp; for (low = data.begin(); low != data.end(); low++) { if (*low == x) { high = low; break; } } if (low == data.end()) { return; } it = data.begin(); while (it != low) { if (*it x) { it++; } else if (*it == x) { data.insert(..