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 / KMP.c
Created November 3, 2016 13:03
KMP 算法
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void compute_prefix(const char *pattern, int next[]) {
int i;
int j = -1;
const int m = strlen(pattern);
next[0] = j;
@tamarous
tamarous / avl_tree.c
Created October 24, 2016 15:41
Avl Tree. 平衡二叉查找树
#include <stdio.h>
#include <stdlib.h>
struct AvlNode;
typedef int ElementType;
typedef struct AvlNode * Position;
typedef Position AvlTree;
AvlTree makeEmpty(AvlTree T);
@tamarous
tamarous / expressionTree.c
Created October 20, 2016 00:53
将表达式转化为表达式树
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
struct TreeNode;
typedef struct TreeNode * ptrToTreeNode;
typedef struct ptrToTreeNode Tree;
struct TreeNode {
char element;
Tree left;
@tamarous
tamarous / midToPost.c
Created October 17, 2016 16:06
将中缀表达式转换为后缀表达式
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
typedef char ElementType;
struct StackRecord;
typedef struct StackRecord *Stack;
int isEmpty(Stack s);
int isFull(Stack s);
@tamarous
tamarous / radixSort.c
Created October 17, 2016 12:43
基数排序
#include <stdlib.h>
#include <stdio.h>
void radixSort(int *arr, int len, int max)
{
int buckets[10][10] = {0};
int order[10] = {0};
int n = 1;
while (n < max)
@tamarous
tamarous / reverseListV2.c
Created October 17, 2016 12:37
反转链表,链表不带头节点
#include <stdio.h>
#include <stdlib.h>
struct Node;
typedef struct Node * ptrToNode;
typedef ptrToNode List,Position;
struct Node
{
int element;
ptrToNode next;
@tamarous
tamarous / reverseList.c
Created October 17, 2016 12:30
反转链表,链表带有头节点
#include <stdio.h>
#include <stdlib.h>
struct Node;
typedef struct Node * ptrToNode;
typedef ptrToNode List,Position;
struct Node
{
int element;
ptrToNode next;
@tamarous
tamarous / list.cpp
Created October 14, 2016 14:10
单链表实现的多项式相加与相乘
#include <stdio.h>
#include <stdlib.h>
struct Node;
typedef struct Node * ptrToNode;
typedef ptrToNode Polynomial;
struct Node{
int cofficient;
int exponent;
ptrToNode next;
@tamarous
tamarous / maxSequenceSumSimplest.cpp
Last active July 22, 2017 02:11
最简单的求最大子序列和算法,时间复杂度:O(N)
/*************************************************************************
> File Name: maxSequenceSumSimplest.cpp
> Author:
> Mail:
> Created Time: 2016年10月10日 星期一 11时02分21秒
************************************************************************/
#include<iostream>
using namespace std;
int maxSequenceSum(const int a[],int N)