Skip to content

Commit

Permalink
Add DFS Search
Browse files Browse the repository at this point in the history
  • Loading branch information
option0417 committed May 1, 2012
1 parent 4dbef9c commit 024cf4a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
33 changes: 33 additions & 0 deletions src/Algorithms/BTreeDFS.c
@@ -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;
}
24 changes: 24 additions & 0 deletions src/Algorithms/BTreeDFS.h
@@ -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_ */
2 changes: 1 addition & 1 deletion src/Others/OPUtils.c
Expand Up @@ -18,7 +18,7 @@ int* getRandomList(int _size) {

srand(time(NULL));
while (index < size) {
list[index++] = rand() % 100000 + 1;
list[index++] = rand() % 10000 + 1;
}

return list;
Expand Down
22 changes: 16 additions & 6 deletions src/main.c
Expand Up @@ -16,26 +16,36 @@
#include "Algorithms/SelectionSort.h"
#include "Algorithms/InsertionSort.h"
#include "Algorithms/QuickSort.h"
#include "Algorithms/BTreeDFS.h"

#define SIZE 100000000
#define SIZE 100000

int main(void) {
//Variables for mesure program performance
clock_t s, f;

int* list = getRandomList(SIZE);
//showList(list, SIZE);
showList(list, SIZE);

//Start record
s = getClock();
printf("Start Time : %ld\n", s);

//Algorithm Function
//bubbleSort(list, SIZE);
//selectionSort(list, SIZE);
//insertionSort(list, SIZE);
quickSort(list, 0, SIZE-1);
//quickSort(list, 0, SIZE-1);
//bTreeTrace(list, 20000, 1234);

//Finish record
f = getClock();
printf("End Time : %ld\n", f);
//system("pause");
//showList(list, SIZE);
printf("Program Execution Time : %ld", f - s);

showList(list, SIZE);

printf("Program Execution Time : %ld", f - s);
free(list);

return EXIT_SUCCESS;
}

0 comments on commit 024cf4a

Please sign in to comment.