crapmyster's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Active Members
Active Posts:
71 (0.08 per day)
Joined:
12-October 11
Profile Views:
2,221
Last Active:
User is offline Nov 24 2013 09:58 PM
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
Icon   crapmyster has not set their status

Posts I've Made

  1. In Topic: WinForms - Controlling a multiple textboxes with an event handler

    Posted 19 Mar 2013

    View PostSkydiver, on 19 March 2013 - 10:29 AM, said:

    Really simple: Whenever a textbox receives the focus, set a class variable that holds on to that reference. In your button click handler, set the text in that textbox that is referred to by that class variable.


    Indeed it is simple. Thanks for the help!
  2. 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;
    
    
  3. In Topic: Problem with adding to a binary tree

    Posted 12 Nov 2012

    View PostSkydiver, on 12 November 2012 - 02:52 PM, said:

    Your loop on line 13 won't stop until current is null. On line 29, you are trying to use that null pointer.


    Surely I need that on line 29 so that data is added to that current node?
  4. 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;
        }
    }
    
    
  5. 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.

Comments

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