Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dbef9c
commit 024cf4a
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
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,33 @@ | ||
/* | ||
* BTreeDFS.c | ||
* | ||
* Created on: May 1, 2012 | ||
* Author: option0417 | ||
*/ | ||
#include "BTreeDFS.h" | ||
|
||
int bTreeTrace(int* root, size_t size, int val) { | ||
static int level = 1; | ||
|
||
size_t cnt = 0; | ||
size_t idx = 0; | ||
for (cnt = 0; cnt < size; cnt++) { | ||
for (idx = cnt; idx < size; idx = idx*2+1) { | ||
if (root[idx] == val) { | ||
return level; | ||
} else { | ||
level++; | ||
} | ||
} | ||
idx--; | ||
idx /= 2; | ||
idx++; | ||
for (; idx > 0; idx/=2) { | ||
if (root[idx] == val) { | ||
return level; | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} |
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,24 @@ | ||
/* | ||
* BTreeDFS.h | ||
* | ||
* Created on: May 1, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#ifndef BTREEDFS_H_ | ||
#define BTREEDFS_H_ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
/* | ||
* root : Root of Tree | ||
* size : Number of Nodes | ||
* val : Value for Search | ||
* return = 0 : Not found | ||
* return = n : Found record and return search times | ||
*/ | ||
int bTreeTrace(int* root, size_t size, int val); | ||
|
||
#endif /* BTREEDFS_H_ */ |
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
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