随笔分类 - 算法导论
摘要:Dijkstra算法:#include#include#include#include#define N 1000#define MAX 1000000using namespace std;int arcs[N][N]; //邻接矩阵//Dijkstra算法(稠密)bool visit[N]...
阅读全文
摘要:欧拉路径(u,v)是否存在: 对于连通无向图,u,v 顶点的度均为奇数,其他顶点的度均为偶数; 对于强连通有向图,其他顶点的出度==入度,u:出度==入度+1,v:入度==出度+1;欧拉回路是否存在: 对于连通无向图,所有顶点的度均为偶数; 对于强连通有向图,所有顶点的出度==入度;计算顶点...
阅读全文
摘要:参考:算法: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...
阅读全文
摘要:参考:算法:c语言实现 一书图的邻接矩阵实现#ifndef GRAPH#define GRAPH/* 图的邻接矩阵实现*/#include#include#includestruct edge{ int v; int w;};struct graph{ int v; int e; int **adj...
阅读全文
摘要:#include#include#include#include#include#define RED 1#define BLACK 0using namespace std;struct node{ int color; int key; node* left; node* right; node...
阅读全文
摘要:#include#includeunsigned int hashIndex1(const char *key, unsigned int tablesize){ unsigned int val = 0; while (*key != '\0') val += *key++; return va...
阅读全文
摘要:#include#include#includetypedef struct _stack{ int* arr; int top, size;}stack;stack createStack(int size){ stack st; st.arr = (int*)malloc(size*sizeof...
阅读全文
摘要:#include#includetypedef struct _ListNode{ int m_nKey; struct _ListNode *m_pNext;}ListNode;//插入节点void InsertNode(ListNode **plistHead, int val){ ListNo...
阅读全文
摘要:#include#include#include#define MAXINT 0x7fffffff#define MININT 0X80000000//字符串中第一个只出现一次的字符char firstSingle(char *str){ int a[255]; memset(a, 0, 255 *...
阅读全文
摘要:/* 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...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文