算法分析与设计
文章平均质量分 58
TDiger
不积跬步无以至千里
展开
-
最小支撑树prim)
《数据结构与算法分析》//2013/07/01 prim#includeusing namespace std;const int INIT=30000;typedef int ** Graph;void InitGraph(Graph &G,int n,int * &visted,int *&D,int *&V){ int i; int j; G=new int *[n原创 2013-07-01 10:09:20 · 1070 阅读 · 0 评论 -
单源点最短距离(Dijkstra)
//2013/06/30>#include#define INIT 300000//表示无穷using namespace std;void InitGraph(Graph &G,int * &distance,int *& visted,int n)//创建图中变量初始化{ int i; int j; G=new int *[n]; for(i=0;原创 2013-06-30 22:48:38 · 989 阅读 · 0 评论 -
拓扑排序
内容《数据结构与算法分析》,核心思想:当访问某个顶点时候,不对该顶点做任何处理,当递归返回到这个顶点时候,打印这个顶点,这将产生一个逆序拓扑序列,最后将逆序序列反转。//2013/06/30基于DFS的拓扑排序#includeusing namespace std;typedef int **Graph;int *visted;int *out;int num=0;vo原创 2013-06-30 16:56:45 · 827 阅读 · 0 评论 -
图的深度遍历(DFS)
#includeusing namespace std;typedef int **Graph;int *visted;void InitGraph(Graph &G,int n){ int i; int j; visted=new int [n]; G=new int *[n]; for(i=0;i<n;++i) G[i]=new int [n]; for(i=0;i<原创 2013-06-30 22:42:44 · 1052 阅读 · 0 评论 -
找出字符串中出现频率最高的字符
方法1:字母a-z,共有26个,建立一个数组,遍历整个字符串, 统计每一个字符个数,找出字符最多那个。#includeusing namespace std;const int N=26; struct Max{ char apla; int data;}; Max findmax(char *a){ Max maxapla; int i;原创 2013-07-02 16:31:11 · 2279 阅读 · 0 评论