Skip to content

Instantly share code, notes, and snippets.

@rickyzhang-cn
rickyzhang-cn / hash_table.h
Created October 20, 2014 13:38
Hash Table的C实现
#define INITIAL_TABLE_SIZE 163
typedef struct hash_item {
void* p_elem;
struct hash_item* next;
} hash_item, *p_hash_item;
typedef struct hash_table {
int item_num;
int table_size;
@rickyzhang-cn
rickyzhang-cn / heap.c
Created October 20, 2014 13:35
优先队列ADT的C实现
#include <stdlib.h>
#include <stdio.h>
#include "heap.h"
PriorityQueue pq_init(int capacity)
{
PriorityQueue H;
H=(PriorityQueue )malloc(sizeof(struct HeapStruct));
@rickyzhang-cn
rickyzhang-cn / hanoi.cpp
Created October 20, 2014 13:30
汉诺塔问题的递归和非递归实现
#include <iostream>
using namespace std;
void hanoi(int n, char src, char bri, char dst)
{
if(n == 1)
{
cout<<"Move"<<n<<"from"<<src<<"to"<<dst<<endl;
}else
{
@rickyzhang-cn
rickyzhang-cn / heap_sort.c
Created October 20, 2014 13:27
堆排序的C实现
#include <stdio.h>
#include <stdlib.h>
void down(int * p, int k, int i)
{
int value=p[i];
int t;
for(t=i*2;t<=k;t=t*2)
{
@rickyzhang-cn
rickyzhang-cn / eight_queue.c
Created October 20, 2014 13:25
八皇后问题的实现
/*
* 回溯法解N皇后问题
* 使用一个一维数组表示皇后的位置
* 其中数组的下标表示皇后所在的行
* 数组元素的值表示皇后所在的列
* 这样设计的棋盘,所有皇后必定不在同一行
*
* 假设前n-1行的皇后已经按照规则排列好
* 那么可以使用回溯法逐个试出第n行皇后的合法位置
* 所有皇后的初始位置都是第0列
@rickyzhang-cn
rickyzhang-cn / build_binarytree.c
Last active August 29, 2015 14:07
重建二叉树
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024
#define true 1
#define false 0
struct bt_node {
int value;
struct bt_node * left;