Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Trying to Create a Binary Search Tree in C with Scanned Values

The first call to addNode appears to work correctly and create the head. However, when initBST calls addNode the second time, addNode recurs on one of these two lines:

    if(ID < head->id){
        return head->left =
addNode(head->left, ID, name, major, year); 
    else if(ID > head->id){
        return head->right =
addNode(head->right, ID, name, major, year); 

Since both head->left and head->right are NULL, the new iteration of addNode will print your head == NULL message, but it creates the new node correctly. The other iteration of addNode (running the above code) sets head->left or head->right correctly, but it then returns that value, which initBST sets as the new head. The relevant part of addNode should look like this:

head->left = addNode(head->left,
ID, name, major, year);
return head;
// with the other one changed as well

Categories : C

Related to : Trying to Create a Binary Search Tree in C with Scanned Values
How Can I Search A Word in A Binary Search Tree?
You'll have to walk the whole tree since you're not searching by id, but you seem to realize that already. To walk the tree in order using recursion, recursively call your function on the left subtree, process the current node, then recursively call the function on the right subtree (checking for NULL appropriately). Example: void listWord(node *tree, char *word) { if (tree) { /* I

Categories : C
Recursive Binary Search in C++
There are two problems with your code: In your binarySearch() method, you are comparing values, not keys. This may be what you wanted but you don't have value 2 stored in your list (see point 2). You insertAfter() method inserts chars that when printed give 0,1,2,3,4,5,6 but in fact their int values (based on which you make the comparison) are the following: 48,49,50,51,52,53,54. I am not sure

Categories : C++
Binary search on list
List has a binary search method but since binary search is so easy to implement and since the IComparator you would need to define is so complex due to the range thing I suggest you implement the binary search method Something like this (NOT TESTED!) public static IPRange BinarySearch(List<IPRange> source, int intIp) { int startIndex = 0; int endIndex = source.Count; while (end

Categories : C#
Binary search equivalent for `find_if`
I believe you're looking for std::binary_search or std::lower_bound.

Categories : C++
how to add a node in a binary search tree
So 2 things NoneType is capitalized: None (all if's you do in create_node) Python string comparison is casesensitive, so when you check for pointer["number"] value you are not really checking the one you set in the create_node method, which it's key is "Number"(capital "N"), being the reason it throws KeyError. Same for "right" and "left".

Categories : Python
Recently Add
Rewrite of IDA decompiled function
Computing the average of grades in C
passing structures to functions
Use semaphores for handling sockets in C
How to search for a string pattern inside html, coding in C?
sprintf invalid format '%d'
Why can't this c program run correctly?
Low Pass filter in C
Child process does not print anything
C: datatypes. sqrt function working with int why?
How to implement Serial Port Profile Link Command used in ConnectBlue Bluetooth Module?
Rerunning cancelled pthread
How to print out a string that is pointed to by a char pointer?
Can unverified scanf call cause an undefined behavior?
nested structures in C
Portable Makevars for R package using C, GSL and OpenMP with help of Rcpp
program doesn't run(getting RUN FINISHED Segmentation fault core dumped)
Finding the sign of a Lua number, from C
Width of symbols created by gcc's objectcopy
Strange behavior when using free in c program
Can't open image C
Strange C code - dynamic arrays?
C program printing weird characters
Fault in decimal to binary in c
How to detect broken pipe on input?
How can I ivestigate use of the register keyword in C?
File scaning with fscanf
why gcc generates "leal -8240(%ebp), %eax; cmpl $1, %eax; ja XXX" instead of jmp instruction?
Wierd Problems With My Own Custom Written Word Search Algorithm
Trouble with making a shell in C
© Copyright 2017 Publishing Limited. All rights reserved.