-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
提交图的最短路径 #162
Open
MineFi
wants to merge
6
commits into
CUCCS:master
Choose a base branch
from
MineFi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
提交图的最短路径 #162
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
8, 3, 1, 6, 4, 5, 7, 10, 14, 19, 22, 30 | ||
|
||
8, 3, 1, 6, 4, 5, 7, 10, 14, 13, 19, 22, 30 | ||
|
||
7, 3, 1, 6, 4, 5, 10, 14, 13, 19, 22, 30 | ||
|
||
7, 3, 1, 6, 4, 10, 14, 13, 19, 22, 30 | ||
|
||
7, 3, 1, 6, 4, 10, 14, 13, 19, 22, 20, 30 | ||
|
||
7, 3, 1, 4, 10, 14, 13, 19, 22, 20, 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include"BSTree.h" | ||
int max = 0; | ||
|
||
bool EQ(KeyType kval, KeyType data) { | ||
if (kval == data) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
bool LT(KeyType kval, KeyType data) { | ||
if (kval != data && kval < data) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
Status preOrderTraverse(BiTree T) { | ||
if (T) { | ||
printf("%d", T->data); | ||
if (T->data != max) { | ||
printf(", "); | ||
} | ||
preOrderTraverse(T->lchild); | ||
preOrderTraverse(T->rchild); | ||
return OK; | ||
} | ||
else { | ||
return ERROR; | ||
} | ||
} | ||
|
||
bool SearchBST(BiTree T, KeyType kval, BiTree f, BiTree *p) { | ||
if (!T) { | ||
*p = f; | ||
return false; | ||
} | ||
else if (EQ(kval, T->data)) { | ||
*p = T; | ||
return true; | ||
} | ||
else if (LT(kval, T->data)) { | ||
return SearchBST(T->lchild, kval, T, p); | ||
} | ||
else { | ||
return SearchBST(T->rchild, kval, T, p); | ||
} | ||
} | ||
|
||
bool InsertBST(BiTree *T, KeyType e, BiTree p) { | ||
BiTree s = NULL; | ||
if (max < e) | ||
{ | ||
max = e; | ||
} | ||
if (!(s = (BiTNode *)malloc(sizeof(BiTNode)))) { | ||
exit(OVERFLOW); | ||
} | ||
if (!(p = (BiTNode *)malloc(sizeof(BiTNode)))) { | ||
exit(OVERFLOW); | ||
} | ||
if (!SearchBST(*T, e, NULL, &p)) { | ||
s->data = e; | ||
s->lchild = s->rchild = NULL; | ||
if (!p) { | ||
*T = s; | ||
} | ||
else if (LT(e, p->data)) { | ||
p->lchild = s; | ||
} | ||
else { | ||
p->rchild = s; | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
Status Delete(BiTree *p) { | ||
BiTree q = NULL; | ||
BiTree s = NULL; | ||
if (!(*p)->rchild) { | ||
q = *p; | ||
(*p) = (*p)->lchild; | ||
} | ||
else if (!(*p)->lchild) { | ||
q = *p; | ||
(*p) = (*p)->rchild; | ||
} | ||
else { | ||
q = *p; | ||
s = (*p)->lchild; | ||
while (s->rchild) { | ||
q = s; | ||
s = s->rchild; | ||
} | ||
(*p)->data = s->data; | ||
if (q != (*p)) { | ||
q->rchild = s->lchild; | ||
} | ||
else { | ||
q->rchild = s->lchild; | ||
} | ||
} | ||
return OK; | ||
} | ||
|
||
bool DeleteBST(BiTree *T, KeyType kval) { | ||
if (!T) { | ||
return false; | ||
} | ||
else { | ||
if (EQ(kval, (*T)->data)) { | ||
Delete(T); | ||
return true; | ||
} | ||
else if (LT(kval, (*T)->data)) { | ||
return DeleteBST(&(*T)->lchild, kval); | ||
} | ||
else { | ||
return DeleteBST(&(*T)->rchild, kval); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef int KeyType; | ||
|
||
typedef enum | ||
{ | ||
false, | ||
true, | ||
}bool; | ||
typedef enum { | ||
OK, | ||
OVERFLOW, | ||
ERROR, | ||
} Status; | ||
typedef struct BiTNode | ||
{ | ||
int data; | ||
struct BiTNode *lchild, *rchild; | ||
}BiTNode, *BiTree; | ||
|
||
bool EQ(KeyType kval, KeyType data); | ||
bool LT(KeyType kval, KeyType data); | ||
Status preOrderTraverse(BiTree T); | ||
bool SearchBST(BiTree T, KeyType kval, BiTree f, BiTree *p); | ||
bool InsertBST(BiTree *T, KeyType e, BiTree p); | ||
Status Delete(BiTree *p); | ||
bool DeleteBST(BiTree *T, KeyType kval); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include"BSTree.h" | ||
|
||
int main() { | ||
char c[30] = { 8, 10, 14, 3, 1, 6, 4, 7, 5, 19, 22, 30 }; | ||
char c1[10] = { 13, 8, 5, 20, 6 }; | ||
int i; | ||
bool flag = 0; | ||
BiTree T = NULL; | ||
BiTree p = NULL; | ||
|
||
for (i = 0; i<12; i++) | ||
{ | ||
InsertBST(&T, c[i], p); | ||
} | ||
|
||
preOrderTraverse(T); | ||
printf("\n\n"); | ||
|
||
for (i = 0; i<5; i++) //5����������ij��� | ||
{ | ||
flag = SearchBST(T, c1[i], NULL, &p); | ||
if (flag == true) { | ||
DeleteBST(&T, c1[i]); | ||
} | ||
else { | ||
InsertBST(&T, c1[i], p); | ||
} | ||
preOrderTraverse(T); | ||
printf("\n\n"); | ||
} | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= =,不好意思理解错了,结果确实是自己复制的.... 修改后会重新提交