Skip to content

Instantly share code, notes, and snippets.

View tamarous's full-sized avatar
🎯
Focusing

Tamarous tamarous

🎯
Focusing
View GitHub Profile
@tamarous
tamarous / hanoi.c
Last active November 3, 2016 14:39
汉诺塔问题
void hanoi(int n ,char source, char dest, char mid)
{
if (n == 1) {
// 如果 n = 1, 那么可以直接从source 挪到 dest
printf("%d from %c to %c\n",n,source,dest);
} else {
// 上面的n-1个,先放到作为缓冲的那个柱子上,好把最下面一个给移开
hanoi(n-1, source, mid, dest);
@tamarous
tamarous / binary_tree.cpp
Created November 3, 2016 14:39
二叉树的各种遍历方法
/*************************************************************************
> File Name: binary_tree.cpp
> Author:
> Mail:
> Created Time: 2016年11月03日 星期四 21时50分39秒
************************************************************************/
#include<iostream>
using namespace std;
#include <stack>
@tamarous
tamarous / rebuild.c
Created November 5, 2016 04:08
从前序和中序中重建后序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#define MAX 64
typedef char elem_t;
typedef struct node_t {
elem_t element;
struct node_t *left;
struct node_t *right;
@tamarous
tamarous / heap.c
Last active March 26, 2019 07:59
二叉堆的插入和删除最小值操作
#include <stdio.h>
#include <stdlib.h>
#define MinPQSize 5
#define MinData -10000
struct HeapStruct;
typedef struct HeapStruct *priorityQueue;
typedef int ElementType;
priorityQueue initialize(int elementsNum);
void destroy(priorityQueue H);
void makeEmpty(priorityQueue H);
@tamarous
tamarous / sort.cpp
Last active January 22, 2018 13:11
快速排序和冒泡排序
void bubbleSort(int array[],int n) {
int i,j,tmp;
for(i = 0;i < n;i++) {
for(j = 0;j < n-i;j++ ) {
if (array[j] > array[j+1]) {
tmp = array[j];
array[j] = array[j+1];
array[j+1] = tmp;
}
}
@tamarous
tamarous / DNA.cpp
Created November 10, 2016 17:05
UVA 1368
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int T,n,m;
#define maxn 1005
#define maxm 52
char DNA[maxm][maxn];
char s[maxn];
void processDNA() {
int count[maxn][4] = {0};
@tamarous
tamarous / YV12ToBGR24_Native.c
Created February 8, 2017 06:51
Convert yuv to bgr
bool YV12ToBGR24_Native(unsigned char* pYUV, unsigned char* pBGR24, int width, int height) {
if (width < 1 || height < 1 || pYUV == NULL || pBGR24 == NULL)
return false;
const long len = width * height;
unsigned char* yData = pYUV;
unsigned char* vData = &yData[len];
unsigned char* uData = &vData[len >> 2];
int bgr[3];
int yIdx, uIdx, vIdx, idx;
@tamarous
tamarous / yuv420_to_argb8888.c
Created February 8, 2017 06:52
使用快速指令集来将YUV转成32位RGB
void yuv420_to_argb8888(uint8_t *pYUV,
uint32_t sy, uint32_t suv,
int width, int height,
uint32_t *rgb, uint32_t srgb) {
uint8_t *yp;
uint8_t *up;
uint8_t *vp;
yp = pYUV;
up = pYUV + width*height;
vp = up + width*height / 4;
@tamarous
tamarous / rbga32_to_rgb24_ssse3.c
Created February 8, 2017 06:53
使用快速指令集来将32位RGB转为24位RGB
void rbga32_to_rgb24_ssse3(uint8_t* dst, uint32_t* src, int width, int height) {
__m128i *d = (__m128i*)dst;
__m128i *s = (__m128i*)src;
__m128i mask = _mm_setr_epi8(0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1);
for (int i = 0; i < width*height; i += 16) {
__m128i sa = _mm_shuffle_epi8(_mm_load_si128(s), mask);
__m128i sb = _mm_shuffle_epi8(_mm_load_si128(s + 1), mask);
__m128i sc = _mm_shuffle_epi8(_mm_load_si128(s + 2), mask);
__m128i sd = _mm_shuffle_epi8(_mm_load_si128(s + 3), mask);
@tamarous
tamarous / Tree.cpp
Last active October 9, 2017 08:59
二叉查找树-DFS与BFS的实现
#include <iostream>
#include <cstddef>
#include <queue>
#include <string>
#include <cstdlib>
#include <stack>
using namespace std;
class Node {
public:
int data;