Sign in to follow this  
  • entries
    156
  • comments
    253
  • views
    85239

A Post

Sign in to follow this  
ildave1

65 views

I am taking a personal & professional development course that became required this semester and today I spent some time reviewing resume's and talking about dress.

It amazes me how many people do not realize how important dressing nice and keeping personal appearance up to par. I hope after my discussion with them that they realize that, like it or not, people judge you by what you are wearing and how good you keep yourself "Maintained"




Finished up a project in my C programming course. Have a peek. This is pretty much emphasizing structures and pointers using C. The program is a Binary Search Tree that will allow you to insert, search, and traverse the tree. If your knew to programming, take a look, put it into your compiler and check it out.

#include
#include

// Structure TREE
typedef struct tree{
int data;
struct tree *left;
struct tree *right;
}TREE;

// Function Prototypes and Member Declarations
TREE* insert(TREE *cur, int num);
int srcNumber(TREE *cur, int num);
int pntTraversal(TREE *root);
int cleanup(TREE *cur);

TREE *cur = NULL;

// Main Function that controls program flow
int main()
{
int done = 0;
int number = 0;
char selection;

while(!done)
{
printf("Enter (i)nsert, (s)earch, inorder (t)raversal, or (q)uit: ");
scanf("%c", &selection);

switch(selection)
{
case 'i':
printf("Enter a number to insert: ");
scanf("%d", &number);
cur = insert(cur, number);
break;
case 's':
printf("Enter a number to search: ");
scanf("%d", &number);
srcNumber(cur, number);
break;
case 't':
pntTraversal(cur);
printf("\n");
break;
case 'q':
done = 1;
break;
default:
break;
}

getchar();
}

// Free Memory Before Exit
cleanup(cur);

// Return a successfull Launch
return 0;
}

/************************************************************
* This function will insert a number that the user inputs
*
* @param cur - The current status of the users BST
* @param num - The number to be inserted
*************************************************************/

TREE* insert(TREE* cur, int num)
{
if(cur == NULL)
{
cur = (TREE*)malloc(sizeof(TREE));
cur->left = NULL;
cur->right = NULL;
cur->data = num;
return cur;
}
else if(num == cur->data)
{
return cur;
}
else if(num < cur->data)
{
cur->left = insert(cur->left, num);
return cur;
}
else if(num > cur->data)
{
cur->right = insert(cur->right, num);
return cur;
}
return 0;
}

/************************************************************
* This function will search for a number within the BST
*
* @param cur - The current status of the users BST
* @param num - The number to be found
*************************************************************/

int srcNumber(TREE* cur, int num)
{
if(cur == NULL)
{
printf("%d is not in the tree\n", num);
}
else if(num == cur->data)
{
printf("%d is in the tree.\n", cur->data);
return num;
}
else if(num < cur->data)
{
return srcNumber(cur->left, num);
}
else if(num > cur->data)
{
return srcNumber(cur->right, num);
}
return 0;
}

/************************************************************
* This function will print the BST, in-order
*
* @param root - The current status of the head of the BST
*************************************************************/

int pntTraversal(TREE* root)
{
if(root == NULL){
return 0;
}

pntTraversal(root->left);
printf("%d ", *root);
pntTraversal(root->right);

return 0;
}

/************************************************************
* This function will release all of the nodes within the BST
*
* @param root - The current status of the users BST
*************************************************************/

int cleanup(TREE* root)
{
if(root == NULL)
{
return 0;
}

cleanup(root->left);

cleanup(root->right);

free(root);

return 0;
}



Compiled in Visual Studio 2005, Academic Version


Other then that, I finally got my Dell XPS which is turning out to be one hell of a great laptop. I have been wanting to get a laptop for quite some time and I finally found one that is not only stylish, but seems to hold up to my abuse. :)

Take Care Everybody
-Dave
Sign in to follow this  


2 Comments


Recommended Comments

About your code: (If you don't want any comments, just ignore this post)

It's a bad idea to have both a global variable and a function variable with the same name. In this case, it's your TREE* cur. (It seems that if you move the global one to be local to main, everything is fine.)

Your style is inconsistent. You put the opening brace on the same line for your TREE struct, but then have it on the next line for your functions, ifs, and whiles. You also use "TREE *cur" in one place, and "TREE* cur" in another.

Please don't think I'm bashing you. I'm just trying to be helpful, and noticing little things like this is something I'm good at.

Share this comment


Link to comment
Oh Hey! No, Not a problem at all Jesse. Feedback is what these replies are all about and trust me, nothing said here will ever amount to the bashing I heard (and sometimes had to give) in the Marines. A good technical term for this would be having "Hard Skin".

I appreciate the gander, I'll definitely keep what you said in mind when I move into my next project.

Thank you,
-Dave

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now