随笔分类 -  数据结构实践

1 2 下一页

Dijkstra算法模板
摘要:Dijkstra算法又称为单源最短路径,所谓单源是在一个有向图中,从一个顶点出发,求该顶点至所有可到达顶点的最短路径问题。设G=(V,E)是一个有向图,V表示顶点,E表示边。它的每一条边(i,j)属于E,都有一个非负权W(I,j),在G中指定一个结点v0,要求把从v0到G的每一个接vj(vj属于V)的最短有向路径找出来(或者指出不存在)。Dijstra算法是运用贪心的策略,从源点开始,不断地通过相联通的点找出到其他点的最短距离基本思想是:设置一个顶点的集合s,并不断地扩充这个集合,一个顶点属于集合s当且仅当从源点到该点的路径已求出。开始时s中仅有源点,并且调整非s中点的最短路径长度,找当前最短 阅读全文

posted @ 2012-08-12 09:04 mycapple 阅读(4523) 评论(0) 推荐(1)

前缀表达式求值
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define N 1100 5 char s[N]; 6 //数字栈的操作 7 typedef struct 8 { 9 float *base; 10 float *top; 11 }SqStack2; 12 int InitStack2(SqStack2 &S) 13 { 14 S.base=(float *)malloc(505*sizeof(float)); 15 S.top=S.base; 16 return 1 阅读全文

posted @ 2012-08-06 12:19 mycapple 阅读(356) 评论(0) 推荐(0)

归并排序
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define FALSE 0 5 #define MAX_NUM 100 6 typedef int Status; 7 typedef int ElemType; 8 typedef struct SqList 9 {10 ElemType r[MAX_NUM];11 int length;12 }SqList;13 void Merge(ElemType SR[],ElemType TR[],int i,int m,int n)14 {15 int. 阅读全文

posted @ 2012-08-03 09:22 mycapple 阅读(235) 评论(0) 推荐(0)

堆排序
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define FALSE 0 5 #define MAX_NUM 100 6 typedef int Status; 7 typedef int ElemType; 8 typedef struct SqList 9 {10 ElemType r[MAX_NUM];11 int length;12 }SqList;13 typedef SqList HeapType;14 Status Exchange(ElemType &a,ElemType 阅读全文

posted @ 2012-08-03 09:21 mycapple 阅读(294) 评论(0) 推荐(0)

最小生成树(普里姆)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define TRUE 1 5 #define FALSE 0 6 #define ERROR -1 7 #define OVERFLOW -2 8 #define INFINITY 65535 9 #define MAX_VERTEX_NUM 2010 typedef int Status;11 typedef char TreeType;12 //定义邻接矩阵数据结构 13 typedef struct14 {15 TreeType vexs[MAX 阅读全文

posted @ 2012-08-03 09:20 mycapple 阅读(288) 评论(0) 推荐(0)

邻接矩阵
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define TRUE 1 5 #define FALSE 0 6 #define ERROR -1 7 #define OVERFLOW -2 8 #define MAX_VERTEX_NUM 20 9 bool visited[MAX_VERTEX_NUM]; 10 typedef int QElemint; 11 typedef int Status; 12 //定义队列数据结构 13 typedef struct QNode 14 { 15 .. 阅读全文

posted @ 2012-08-03 09:19 mycapple 阅读(380) 评论(0) 推荐(0)

最短路径(Dijkstra)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define TRUE 1 5 #define FALSE 0 6 #define ERROR -1 7 #define OVERFLOW -2 8 #define INFINITY 65535 9 #define MAX_VERTEX_NUM 10 10 typedef int Status; 11 typedef char TreeType; 12 int P[MAX_VERTEX_NUM];//用于存放最短路径,P[i]存放i的前驱结点序号 13 阅读全文

posted @ 2012-08-03 09:19 mycapple 阅读(275) 评论(0) 推荐(0)

链式堆栈
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define Stack_Size 100 4 #define Stackincrement 10 5 #define ok 1 6 #define error -1 7 #define overflow 2 8 #define TRUE 1 9 #define FALSE 010 typedef int status;11 typedef struct12 {13 int *base;14 int *top;15 int stacksize;16 }SqStack;17 statu 阅读全文

posted @ 2012-08-03 09:18 mycapple 阅读(338) 评论(0) 推荐(0)

顺序堆栈
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define Stack_Size 100 4 #define StackIncrement 10 5 #define OK 1 6 #define TRUE 1 7 #define FALSE 0 8 #define ERROR -1 9 #define OVERFLOW -210 typedef int Status;11 typedef struct12 {13 int *base;14 int *top;15 int stacksize;16 }SqStack;17 Sta. 阅读全文

posted @ 2012-08-03 09:17 mycapple 阅读(325) 评论(0) 推荐(0)

改进的KMP模式匹配算法
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int next[12],la,lb; 4 void GetNext(char T[]) 5 { 6 int j=1,k=0; 7 next[1]=0; 8 while(j<=la) 9 { 10 if(k==0||T[j]==T[k])11 { 12 ++j;13 ++k;14 if(T[k]==T[j])15 next[j]=next[k... 阅读全文

posted @ 2012-08-03 09:16 mycapple 阅读(412) 评论(0) 推荐(0)

摘要:1 #include<> 2 typedef struct 3 { 4 char *ch; 5 int length; 6 }HString; 7 Status StrAssign(Hstring &T,char *chars) 8 { 9 if(T.ch) free(T.ch);10 for(i=0,c=chars;c;i++,c++)11 if(!i)12 {13 T.ch=NULL;14 T.length=0;15 }16 else{17 if(!(T.ch=(char *)... 阅读全文

posted @ 2012-08-03 09:15 mycapple 阅读(241) 评论(0) 推荐(0)

已知二叉树的前序与中序遍历创建二叉树
摘要:1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 struct Node 7 { 8 char data; 9 Node *lchild;10 Node *rchild;11 };12 Node *CreatTree(string pre,string in)13 {14 Node *root=NULL;15 if(pre.length()>0)16 {17 root... 阅读全文

posted @ 2012-08-03 09:14 mycapple 阅读(381) 评论(0) 推荐(0)

内部排序H
摘要:1 #include<stdio.h> 2 #include<math.h> 3 #include<iostream.h> 4 #include<stdlib.h> 5 #define OK 1 6 #define FALSE 0 7 #define MAX_NUM 100 8 typedef int Status; 9 typedef int ElemType; 10 typedef struct SqList 11 { 12 ElemType r[MAX_NUM]; 13 int length; 14 }SqList; 15 typedef 阅读全文

posted @ 2012-08-03 08:21 mycapple 阅读(345) 评论(0) 推荐(0)

邻接表
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<iostream.h> 4 #define OK 1 5 #define TRUE 1 6 #define FALSE 0 7 #define ERROR -1 8 #define OVERFLOW -2 9 #define MAX_VEX_NUM 20 10 using namespace std; 11 typedef int Status; 12 //定义邻接表存储类型 13 typedef char VexType; 14 typedef stru 阅读全文

posted @ 2012-08-03 08:20 mycapple 阅读(2877) 评论(0) 推荐(0)

二叉排序树M
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define OK 1 4 #define TRUE 1 5 #define FALSE 0 6 #define ERROR -1 7 #define OVERFLOW -2 8 typedef int Status; 9 typedef int KeyType; 10 typedef int TElemType; 11 typedef struct BiTNode{ 12 TElemType data; 13 BiTNode *lchild,*rchild; 14 }... 阅读全文

posted @ 2012-08-03 08:19 mycapple 阅读(371) 评论(0) 推荐(0)

二叉树递归遍历操作M
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define ok 1 4 #define error 0 5 typedef int status; 6 typedef char TElemType; 7 typedef struct BiTNode 8 { 9 TElemType data; 10 struct BiTNode *lchild,*rchild; 11 }BiTNode,*BiTree; 12 13 void InitBiTree(BiTree &T) 14 { 15 T=NULL; 16 } ... 阅读全文

posted @ 2012-08-03 08:18 mycapple 阅读(349) 评论(0) 推荐(0)

二叉树非递归M
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define Stack_Size 100 4 #define StackIncrement 10 5 #define OK 1 6 #define TRUE 1 7 #define FALSE 0 8 #define ERROR 0 9 #define OVERFLOW -2 10 typedef int Status; 11 typedef char TElemType; 12 typedef struct BiTNode 13 { 14 TElemType data; 15.. 阅读全文

posted @ 2012-08-03 08:18 mycapple 阅读(324) 评论(0) 推荐(0)

稀疏矩阵的十字链表存储表示和实现
摘要:1 #include <stdio.h> 2 #include <malloc.h> 3 typedef int ElemType;// 稀疏矩阵的十字链表存储表示 4 typedef struct OLNode 5 { 6 int i,j; // 该非零元的行和列下标 7 ElemType e; // 非零元素值 8 struct OLNode *right,*down; // 该非零元所在行表和列表的后继链域 9 }OLNode, *OLink; 10 typedef struct// 行和列链表头指针向量基址,由CreatS... 阅读全文

posted @ 2012-08-03 08:17 mycapple 阅读(10810) 评论(0) 推荐(1)

十字链表M
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define TRUE 1 4 #define FALSE -1 5 #define ERROR 0 6 #define OK 1 7 #define OVERFLOW -2 8 #define LEN1 sizeof(OLink) 9 #define LEN2 sizeof(OLNode) 10 typedef int Status; 11 typedef int ElemType; 12 typedef struct OLNode{ 13 int i,j; 14 El... 阅读全文

posted @ 2012-08-03 08:16 mycapple 阅读(640) 评论(0) 推荐(0)

链式队列M
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define ok 1 4 #define error 0 5 #define overflow -1 6 #define TRUE 1 7 #define FALSE 0 8 #define status int 9 typedef struct QNode 10 { int data; 11 struct QNode *next; 12 }QNode,*QueuePtr; 13 typedef struct 14 { QueuePtr front; 15 QueueP... 阅读全文

posted @ 2012-08-03 08:14 mycapple 阅读(177) 评论(0) 推荐(0)

1 2 下一页

导航