crapmyster's Profile
Reputation: 0
Apprentice
- Group:
- Active Members
- Active Posts:
- 70 (0.12 per day)
- Joined:
- 12-October 11
- Profile Views:
- 458
- Last Active:
Mar 20 2013 02:50 AM- Currently:
- Offline
Previous Fields
- Country:
- Who Cares
- OS Preference:
- Windows
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- XBox
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: WinForms - Controlling a multiple textboxes with an event handler
Posted 19 Mar 2013
-
In Topic: Problem with adding to a binary tree
Posted 12 Nov 2012
Still can't get it and confused. This is my thinking. You start at the root node and you add data to it. The if you want to add data which is smaller you go to the left subtree. So because I have defined current as equal to the root node I need to get to that left subtree node. So I do this;
current = current->left;
Since then I'm at the a node which is NULL I add data to this node like this:
current->item = data;
-
In Topic: Problem with adding to a binary tree
Posted 12 Nov 2012
-
In Topic: Problem with adding to a binary tree
Posted 12 Nov 2012
Hello,
I'm running into some more trouble with this add method. Just trying to do the second part. I get an error something to do with not allocating memory or something like that on the line. Could you point me in the right direction please.
current->item = data;
struct TreeNode *insertion(int data, TreeNode *current) { if(root == NULL) { root = (struct TreeNode*)malloc(sizeof(struct TreeNode)); root->item = data; root->left = NULL; root->right = NULL; } else { current = root; while(current != NULL) { if (data == current->item) { printf("No Duplicate Values."); return 0; } else if(data < current->item) { current = current->left; } else if(data > current->item) { current = current->right; } } current->item = data; } } -
In Topic: Problem with adding to a binary tree
Posted 12 Nov 2012
Hello,
Don't worry I got it? Thanks for jogging my memory.
Solution:
#include <stdio.h> #include <stdlib.h> typedef struct TreeNode { int item; // The data in this node. struct TreeNode *left; // Pointer to the left subtree. struct TreeNode *right; // Pointer to the right subtree. }TreeNode; TreeNode *root = NULL; struct TreeNode *insertion(int data) { if(root == NULL) { root = (struct TreeNode*)malloc(sizeof(struct TreeNode)); root->item = data; root->left = NULL; root->right = NULL; } } void print(struct TreeNode *node) { if(node == NULL) { return; } print(node->left); printf("%d ",node->item); print(node->right); } void menu() { int temp = 1; while(temp == 1) { //Prints out the Menu int i; printf(""); printf("*** Binary Tree Assignment ***\n"); printf("Press 'i' to insert an element into the hash table\n"); printf("Press 'd' to delete an element from the hash table\n"); printf("Press 'l' to look up an element in the hash table\n"); printf("Press 's' to obtain the size of the table\n"); printf("Press 'p' to print the current table\n"); printf("Press 'e' to exit from the program\n"); printf("Enter a choice:\n"); char input; scanf("%c", &input); //Getting user input for there selection switch(input) { //Insertion case 'i': printf("Type the integer you wish to enter into the hashTable:\n"); scanf("%d", &i); insertion(5); break; //Deletion case 'd': printf("Type the integer you wish to delete from the hashTable:\n"); scanf("%d", &i); break; //Size case 's': break; //Print case 'p': print(root); break; //Exit case 'e': temp = 0; break; //If incorrect selection is made default: printf("Error: Wrong selection, choose again\n"); break; } } } int main() { menu(); return 0; }
My Information
- Member Title:
- D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Click here to e-mail me
Friends
crapmyster hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
crapmyster has no profile comments yet. Why not say hello?