This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DFS | |
void search(Node root) { | |
if (root == NULL) { | |
return; | |
} | |
visit(root); | |
root.visited = true; | |
foreach (Node n in root.adjacent) { | |
if (n.visited = false) { | |
search(n); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the ith bit of num. | |
bool getBit(int num, int i) { | |
return (num & (1 << i)) != 0; | |
} | |
// Set the ith bit of num. | |
int setBit(int num, int i) { | |
return num | (1 << i); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int findKthLargest(vector<int>& nums, int k) { | |
int lo = 0; | |
int high = (int)nums.size() - 1; | |
for(; lo < high; ) { | |
int i = lo, j = high; | |
int pivot = nums[lo]; | |
while(i < j) { | |
while(i < j && pivot >= nums[j]) { | |
j--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int quickSelect(vector<int> &nums, int k) { | |
int lo = 0; | |
int high = (int)nums.size() - 1; | |
for(; lo < high; ) { | |
int i = lo, j = high; | |
int pivot = nums[lo]; | |
while(i < j) { | |
while( i < j && pivot <= nums[j]) { | |
j--; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------- Selection Sort---------------------// | |
void selectionSort(vector<int> &num) { | |
int size = num.size(); | |
for(int i = 0; i < size ; i++) { | |
int min = i; | |
for(int j = i + 1; j < size; j++) { | |
if(num[j] < num[min]) { | |
min = j; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <stdlib.h> | |
void build_post(const char *pre, const char *in, const int n, char *post) { | |
int left_len = strchr(in, pre[0]) - in; | |
if (n <= 0) { | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GLHelper.h" | |
#include <android/native_window.h> | |
const char* TEXTURE_UNIFORMS[] = {"y_tex", "u_tex", "v_tex"}; | |
GLuint yuvTextures[3]; | |
#define glCheckError() glCheckError_(__LINE__) | |
void glCheckError_(int line) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef GLHELPER_H | |
#define GLHELPER_H | |
#include <EGL/egl.h> | |
#include <EGL/eglext.h> | |
#include <GLES2/gl2.h> | |
#include <GLES2/gl2ext.h> | |
#include <vector> | |
#include <pthread.h> | |
#include "MyGLCamera.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CStopwatch { | |
public: | |
CStopwatch() { | |
QueryPerformanceFrequency(&m_liPerfFreq); | |
} | |
void Start() { | |
QueryPerformanceCounter(& m_liPerfStart); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 打印链表中的元素 | |
void Print(Node *head) { | |
if (head == NULL) { | |
return; | |
} | |
Node *ptr = head->next; | |
while(ptr != NULL) { | |
cout << ptr->data << endl; | |
ptr = ptr->next; |