useless comment:
OW my eyes, they hurt
like looking over my 52 page report on achondroplasia all over again.
I am going to code it right now:
Code:
#include "defs.h"
int main()
{
Tree root = NULL;
TreeNode* temp;
//these are the variables being read in to the patient record(s)
int i;
unsigned long SSN;
char fname[8];
char lname[10];
int DOB;
char doc[6];
char ins[9];
char allergy[15];
char med_history[15];
char dates[9];
//these are the values needed for the search to work
Position search_val;
unsigned long key_SSN;
(void) printf("Welcome to the sample tree program!!\n");
(void) printf("Please enter values for the patient records.\n");
for (i = 0; i < 3; i++)
{
temp = malloc(sizeof(TreeNode));
(void) printf("the SSN number to enter is: \n");
(void) scanf("%lu", &SSN);
temp->SSN = SSN;
(void) printf("the first name is: \n");
(void) scanf("%s", &fname);
temp->fname = fname;
(void) printf("the last name is: \n");
(void) scanf("%s", &lname);
temp->lname = lname;
(void) printf("the DOB is: \n");
(void) scanf("%d", &DOB);
temp->DOB = DOB;
(void) printf("the primary physician is: \n");
(void) scanf("%s", &doc);
temp->doc = doc;
(void) printf("the insurance provider is: \n");
(void) scanf("%s", &ins);
temp->ins = ins;
(void) printf("the allergies are: \n");
(void) scanf("%s", &allergy);
(void) printf("the med history is: \n");
(void) scanf("%s", &med_history);
temp->med_history = med_history;
(void) printf("the med dates are: \n");
(void) scanf("%s", &dates);
temp->dates = dates;
temp->left = NULL;
temp->right = NULL;
root = insert(root, temp);
printf("insert successful\n");
printf("root->SSN = %lu\n", root->SSN);
printf("root->name = %s\n", root->fname);
printf("root->lname = %s\n", root->lname);
}
(void) printf("Please enter the patient social security
# to search: ");
(void) scanf("%lu", &key_SSN); //enter a number to be searched
search_val = search(key_SSN, root);
if (search_val == NULL) //if its not found, 0 is returned
printf("This value was not on the tree.\n");
else
{ //if it is found, print it
printf("patient record was found.\n");
printf("social security num: %lu\n", search_val->SSN);
printf("patient name is: %s\n", search_val->fname);
}
(void) printf("The tree values are: \n");
inorder(root); //traverse the tree inorder and print values
printf("****\n");
return 0;
}
/************************************************/
/******these are the functions called from main***********/
#include "defs.h"
void destroy(TreeNode* root)
{
free (root); //not sure about this yet
}
/************************************************/
TreeNode* insert(TreeNode* root, TreeNode* temp)
{
if (root == NULL)
{
root = temp;
}
else
{
if (temp->SSN < root->SSN)
root->left = insert(root->left, temp);
else if (temp->SSN > root->SSN)
root->right = insert(root->right, temp);
}
return root;
}
/************************************************/
Position search(unsigned long key_SSN, Tree root)
{
if (root != NULL)
{
if (key_SSN == root->SSN)
return root;
else if (key_SSN < root->SSN)
return (search(key_SSN, root->left));
else if (key_SSN > root->SSN)
return (search(key_SSN, root->right));
else
return NULL;
}
}
/**************************************************/
void inorder(Tree root)
{
if (root != NULL)
{
inorder(root->left);
printf("patient SSN: %lu\n", root->SSN);
printf("patient lname is: %s\n", root->lname);
printf("\n");
inorder(root->right);
}
}
/**************************************************/
/*************this is the definition file********************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
/*notes on definitins in the structure
fname = first name
lname = last name
DOB = date of birth
SSN = socsecnum
doc = primary physician
ins = insurance
*/
typedef char* string;
typedef struct TreeNode
{
unsigned long SSN;
string fname;
string lname;
int DOB;
string doc;
string ins;
string allergy;
string med_history;
string dates;
struct TreeNode* left;
struct TreeNode* right;
}TreeNode;
typedef TreeNode* Tree;
typedef TreeNode* Position;
//function prototypes
void destroy(TreeNode*);
Tree insert(TreeNode*, TreeNode*);
Position search(unsigned long, Tree);
void inorder(Tree);