Skip to content

Instantly share code, notes, and snippets.

View tamarous's full-sized avatar
🎯
Focusing

Tamarous tamarous

🎯
Focusing
View GitHub Profile
@tamarous
tamarous / maxSequenceSum.cpp
Last active October 10, 2016 12:53
求最大子序列和,如果求出来的值为负数,则返回0。时间复杂度:O(NlogN)
#include <iostream>
using namespace std;
int max(int a,int b,int c)
{
return a>b?(a>c?a:c):(c>b?c:b);
}
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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;