随笔分类 -  算法导论

摘要:Dijkstra算法:#include#include#include#include#define N 1000#define MAX 1000000using namespace std;int arcs[N][N]; //邻接矩阵//Dijkstra算法(稠密)bool visit[N]... 阅读全文
posted @ 2015-08-26 11:32 湛雷冲 阅读(165) 评论(0) 推荐(0) 编辑
摘要:欧拉路径(u,v)是否存在: 对于连通无向图,u,v 顶点的度均为奇数,其他顶点的度均为偶数; 对于强连通有向图,其他顶点的出度==入度,u:出度==入度+1,v:入度==出度+1;欧拉回路是否存在: 对于连通无向图,所有顶点的度均为偶数; 对于强连通有向图,所有顶点的出度==入度;计算顶点... 阅读全文
posted @ 2015-08-25 15:38 湛雷冲 阅读(1220) 评论(0) 推荐(0) 编辑
摘要:参考:算法:C语言实现 一书实现:#ifndef GRAPH#define GRAPH#include#includestruct edge{ int v; int w;};struct node{ int v; node* next;};struct graph{ int v; int e; no... 阅读全文
posted @ 2015-08-24 21:07 湛雷冲 阅读(1174) 评论(0) 推荐(0) 编辑
摘要:参考:算法:c语言实现 一书图的邻接矩阵实现#ifndef GRAPH#define GRAPH/* 图的邻接矩阵实现*/#include#include#includestruct edge{ int v; int w;};struct graph{ int v; int e; int **adj... 阅读全文
posted @ 2015-08-24 20:11 湛雷冲 阅读(489) 评论(0) 推荐(0) 编辑
摘要:#include#include#include#include#include#define RED 1#define BLACK 0using namespace std;struct node{ int color; int key; node* left; node* right; node... 阅读全文
posted @ 2015-08-18 13:12 湛雷冲 阅读(146) 评论(0) 推荐(0) 编辑
摘要:#include#includeunsigned int hashIndex1(const char *key, unsigned int tablesize){ unsigned int val = 0; while (*key != '\0') val += *key++; return va... 阅读全文
posted @ 2015-08-03 10:40 湛雷冲 阅读(118) 评论(0) 推荐(0) 编辑
摘要:#include#include#includetypedef struct _stack{ int* arr; int top, size;}stack;stack createStack(int size){ stack st; st.arr = (int*)malloc(size*sizeof... 阅读全文
posted @ 2015-08-02 18:56 湛雷冲 阅读(97) 评论(0) 推荐(0) 编辑
摘要:#include#includetypedef struct _ListNode{ int m_nKey; struct _ListNode *m_pNext;}ListNode;//插入节点void InsertNode(ListNode **plistHead, int val){ ListNo... 阅读全文
posted @ 2015-08-02 13:36 湛雷冲 阅读(204) 评论(0) 推荐(0) 编辑
摘要:#include#include#include#define MAXINT 0x7fffffff#define MININT 0X80000000//字符串中第一个只出现一次的字符char firstSingle(char *str){ int a[255]; memset(a, 0, 255 *... 阅读全文
posted @ 2015-08-01 09:38 湛雷冲 阅读(122) 评论(0) 推荐(0) 编辑
摘要:/* fi表示第i行的最左最小元素的列小标,则有f0#includeusing namespace std;void findOddMin(vector> &a, int m, int n, vector &r){ int len = r.size(); vector tmp; for (int i... 阅读全文
posted @ 2015-07-31 19:56 湛雷冲 阅读(461) 评论(0) 推荐(0) 编辑
摘要:#include#include#include#include#define MAXINT (1= 0 && a[j]>tmp){ a[j + 1] = a[j]; --j; } a[j + 1] = tmp; }}void merge(int *a, int p, int q, in... 阅读全文
posted @ 2015-07-31 15:30 湛雷冲 阅读(244) 评论(0) 推荐(0) 编辑
摘要:#include#include#includevoid swap(int *a, int i, int j){ int tmp = a[i]; a[i] = a[j]; a[j] = tmp;}void BubbleSort(int *a, int n){ for (int... 阅读全文
posted @ 2015-07-31 10:34 湛雷冲 阅读(212) 评论(0) 推荐(0) 编辑
摘要:#include#include#includeusing namespace std;void swap(int *a, int i, int j){ int tmp = a[i]; a[i] = a[j]; a[j] = tmp;}int partition(int *a, i... 阅读全文
posted @ 2015-07-31 10:16 湛雷冲 阅读(371) 评论(0) 推荐(0) 编辑
摘要:#include#include#include#define leftChild(i) (2*(i)+1)//交换void swap(int *a, int i, int j){ int tmp = a[i]; a[i] = a[j]; a[j] = tmp;}//堆下溯void... 阅读全文
posted @ 2015-07-30 10:30 湛雷冲 阅读(336) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示