Skip to content

Instantly share code, notes, and snippets.

View hiepph's full-sized avatar

Hiep Pham hiepph

View GitHub Profile
@hiepph
hiepph / avl.h
Last active August 29, 2015 14:25
[C library] AVL (auto-balanced Binary Search Tree): Insertion + Deletion + Traversal Print
/** AVL (auto-balanced BST)
--------
Edit: keyType
--------
Rewrite: MAX function, Traversal Print
**/
#include<stdlib.h>
// Edit // typedef ... keyType;
// An AVL tree node //
/**
String Pattern Matching:
1, Brute Force Matching
2, Boyer Moore Matching
3, KMP Matching
* * * * * * * * * * * * *
T: string size n
P: pattern size m
* * * * * * * * * * * * *
**/
/** Sorting: Insertion & Bubble & Selection
(Ascending ver.)
[Update 08.13.15]: Quick Sort + Merge Sort
- - -
Note: use for compare numbers or chars (rewrite for compare strings)
**/
/*** Edit *///
typedef struct
{
/**
Heap Sort
* * * * *
A heap sort is a complete binary tree so:
// (index) left child = 2 * parent,
// (index) right child = 2 * parent + 1;
* * * * *
Note: heap uses 1-base index: [1 ... n]
// so list index k would be list[k - 1]
* * * * *
@hiepph
hiepph / stack_list.c
Last active September 29, 2015 14:04
Stack Implementation using Single Linked List
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "stack_list.h"
stack_t *Initialize()
{
stack_t *top = NULL;
return top;
}
@hiepph
hiepph / add_large_num.c
Last active September 29, 2015 14:05
Calculate sum of very large numbers
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "stack_list.h"
/* Check if stacks holding numbers are all empty */
int AllEmpty(stack_t **stack, int n)
{
int i;
for(i = 0; i < n; i++) {
@hiepph
hiepph / stack_array.c
Created September 28, 2015 11:44
Stack Implementation using Array
#include <stdio.h>
#include <stdlib.h>
#include "stack_array.h"
void Initialize()
{
top = 0;
}
int Empty()
@hiepph
hiepph / stack_structure.c
Created September 28, 2015 11:45
Stack Implementation using Structure
#include <stdio.h>
#include <stdlib.h>
#include "stack_structure.h"
void Initialize(stack_t *stack)
{
stack->top = 0;
}
// Note: stack is a structure, so if I want to
// change it, i must point to it
@hiepph
hiepph / dll.h
Created September 28, 2015 11:46
[Header File] Doubly Linked LIst Implementation
#ifndef DLL_H
#define DLL_H
#include<stdlib.h>
typedef ... data_t;
/* Node of a DLL */
typedef struct DLLNode
{
@hiepph
hiepph / sll.h
Created September 28, 2015 11:48
[Header File] Single Linked List Implementation
/** Singly Linked List (include Sort Ascending)
insert, remove, add, count source code
**/
#ifndef SLL_H
#define SLL_H
typedef ... data_t;
struct node