Skip to content

Commit 645d9de

Browse files
committedAug 5, 2017
init update
0 parents  commit 645d9de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7734
-0
lines changed
 

‎BIThrTree.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//线索二叉树
2+
typedef struct BiThrNode
3+
{
4+
TelemType data;
5+
struct BiThrNode *lchild, *rchild;
6+
int LTag,RTag;
7+
};BiThrNode,*BiThrTree;
8+
//以结点p为根的子树中序线索化
9+
void InThreading(BiThrTree p)
10+
{//pre是全局变量,初始化时其右孩子指针为空,便于左树的最左点开始建线索
11+
if(p)
12+
{
13+
InThreading(p->lchild);
14+
if(!p->lchild)
15+
{
16+
p->LTag = 1;
17+
p->lchild = pre;
18+
}
19+
if(!pre->rchild)
20+
{
21+
pre->RTag = 1;
22+
pre->rchild = p;
23+
}
24+
pre = p;
25+
InOrderThreading(p->rchild);
26+
}
27+
}
28+
//带头结点的中序线索化
29+
void InOrderThreading(BiThrTree &Thrt, BiThrTree T)
30+
{
31+
Thrt = new BiThrNode;
32+
Thrt->LTag = 0;
33+
Thrt->RTag = 1;
34+
Thrt->rchild = Thrt;
35+
if(!T) Thrt->rchild = Thrt;
36+
else
37+
{
38+
Thrt->lchild = T;
39+
pre = Thrt;
40+
InTreading(T);
41+
pre->rchild = Thrt;
42+
pre->RTag = 1;
43+
Thrt->rchild = pre;
44+
}
45+
}

‎BellmanFord.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bool BellmanFord(int MAX_VERTEXS, int MAX_EDGES, int v)
2+
{//Single sourse all destination shortest paths with negative edge lengths
3+
for(int i=0;i<MAX_VERTEXS;i++)
4+
dist[i] = length[v][i];//initialize dist
5+
for(int k=2; k<MAX_VERTEXS; k++)
6+
for(int j=0;j<MAX_EDGES; j++)
7+
{
8+
if(dist[j].u!=INFINIT&&dist[edge[j].u]+length[edge[j].u][edge[j].v]<dist[edge[j].v])
9+
dist[edge[j].v] = dist[edge[j].u]+length[edge[j].u][edge[j].v];
10+
}
11+
for(int i=0; i<MAX_EDGES; i++)
12+
if(dist[j].u!=INFINIT&&dist[edge[i].u]+length[edge[i].u][edge[i].v]<dist[edge[i].v])
13+
return FAlSE;
14+
return TRUE;
15+
}

0 commit comments

Comments
 (0)
Please sign in to comment.