-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
final term assignment 3rd submit implemented features - print member list - add new member - remove member - edit member data - search member - save member data to file - read member data from file
- Loading branch information
Showing
16 changed files
with
622 additions
and
149 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,69 @@ | ||
#include "binarySearchTree.h" | ||
|
||
NODE * findNode(NODE * rootNode, int key) | ||
{ | ||
if (rootNode == NULL) | ||
return NULL; | ||
|
||
if (key == rootNode->key) | ||
return rootNode; | ||
else if (key < rootNode->key) | ||
return findNode(rootNode->left, key); | ||
else if (key > rootNode->key) | ||
return findNode(rootNode->right, key); | ||
} | ||
|
||
NODE * createNode(int key, NODEDATA * value) | ||
{ | ||
NODE * node = malloc(sizeof(NODE)); | ||
node->key = key; | ||
node->value = value; | ||
node->left = NULL; | ||
node->right = NULL; | ||
return node; | ||
} | ||
|
||
NODE ** findPosition(NODE * rootNode, int key) | ||
{ | ||
NODE ** targetPos = NULL; | ||
|
||
if (!rootNode) | ||
return NULL; | ||
|
||
if (key < rootNode->key) | ||
targetPos = &(rootNode->left); | ||
else if (key > rootNode->key) | ||
targetPos = &(rootNode->right); | ||
else if (key == rootNode->key) | ||
return NULL; | ||
|
||
if (*targetPos) | ||
return findPosition(*targetPos, key); | ||
else | ||
return targetPos; | ||
} | ||
|
||
void insertNode(NODE * rootNode, int key, NODEDATA * value) | ||
{ | ||
NODE * newNode = createNode(key, value); | ||
NODE ** newNodePos = findPosition(rootNode, key); | ||
|
||
if (newNodePos != NULL) | ||
*newNodePos = newNode; | ||
else | ||
throwException(2); | ||
} | ||
|
||
void deleteNode(NODE * rootNode, int key) | ||
{ | ||
} | ||
|
||
void traverseNode(NODE * rootNode, void(*callbackFunc)(NODEDATA *)) | ||
{ | ||
if (rootNode == NULL) | ||
return; | ||
|
||
traverseNode(rootNode->left, callbackFunc); | ||
callbackFunc(rootNode->value); | ||
traverseNode(rootNode->right, callbackFunc); | ||
} |
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 @@ | ||
#ifndef __BINARYSEARCHTREE_H__ | ||
#define __BINARYSEARCHTREE_H__ | ||
|
||
#include "common.h" | ||
|
||
#include "person.h" | ||
typedef struct _NODEDATA { | ||
PERSON * member; | ||
} NODEDATA; | ||
|
||
typedef struct _NODE { | ||
int key; | ||
NODEDATA * value; | ||
struct _NODE * left; | ||
struct _NODE * right; | ||
} NODE; | ||
|
||
NODE * createNode(int key, NODEDATA * value); | ||
NODE * findNode(NODE * rootNode, int key); | ||
void insertNode(NODE * rootNode, int key, NODEDATA * value); | ||
void deleteNode(NODE * rootNode, int key); | ||
void traverseNode(NODE * rootNode, void(*callbackFunc)(NODEDATA *)); | ||
|
||
#endif |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,7 @@ | |
#define PHONE_NOT_DIGIT 2 | ||
#define PHONE_DUPLICATED 3 | ||
|
||
// exception code | ||
#define KEY_IS_DUPLICATED 1 | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.