and solution:
int within_range (data_t value, data_t low, data_t hi)
{
if (((cmp (value, low)) >= 0) && ((cmp (value, hi)) <= 0))
return 1;
else
return 0;
}
Type: Posts; User: qubit67
and solution:
int within_range (data_t value, data_t low, data_t hi)
{
if (((cmp (value, low)) >= 0) && ((cmp (value, hi)) <= 0))
return 1;
else
return 0;
}
thats right iMalc, I want to count the nodes from the low value to the hi value in the tree, and the error is:
Enter int values into a BST:
0 1 2 3 4 5 6 7 8 9
for what range would you like...
I am coding a range function for a BST, can some one help me with what I'm doing wrong here?
typedef int data_t;
typedef struct bnode bstree_t;
struct bnode
{
data_t data;
bstree_t...
In concluding this thread, It saddens me to see how people can act as a hinderance to someone trying to figure out something. Instead of SIMPLE answers and support, I had an uphill battle with the...
this works too:
list_t *matches (bstree_t *index_tree, char *prefix)
{
int len, compare;
bstree_t *current_node, *sub_tree;
list_t *list;
list = make_empty_list ();
ok, so I have found that the best approach to the matches function is to not make it recursive, but to have it call another function that is recursive, and pass it the list to insert the phrases into.
My logic is that matches searches from the root of the whole tree down each level through each node using the compare function to find a value that matches. The search starts from the root and moves...
I know, I get so KraZy sometimes...
Ok, sorry for bumping, I just hate being avoided.... ;P
trust me, i am a step ahead...
oh, and again, thanks for the help
I will bump my thread if i have to, and I have to.
So, take your your thumb out of your a&& and give me a hand here, or leave me alone, wont make a difference... Over the last week I have grown...
hello?
For example :
Enter phrases to input to the tree:
alpha
beta
cappa
nequ
neqi
I dont think I understand what you mean by append. If you mean at the end, I would have to make a new list called sublist and dereference the right pointers to their coeerct positions:
...
I dont have a variable called sublist, I guess I need to create a new list_t pointer called sublist,
sublist = make_empty_list ();
to append list to sublist:
list->foot->next = sublist->head
how to append sublist to list?
thanks Salem
thanks for the suggestions. I have re-written the function and it is a semi working function :
list_t *insert_into_list (list_t *list, bstree_t *sub_tree)
{
if (sub_tree == NULL)
{...
The generic functions are from my lecturer and his style was to cast just to make the code easier to understand for noobiez like me, I have removerd them now.
I dont understand what you mean I...
I have this so far, but I'm getting a segfault...
Please help me!
list_t *insert_at_foot (list_t *list, char *value)
{
node_t *new;
assert(list != NULL);
new = (node_t *)...
the function list_t *matches(btree_t tree, char *prefix) takes a BST and searches it for phrases that begin with the same prefix, then inserts the phrases that match into a linked list in...
tnx zacs7, I looked through the term, and suddenly... it all became clearer.... and for casting malloc, Salem, point agreed, will ammend my code.
qubz
yes thanks Salem, I have a fully working function.
I dont think that i can always terminate the string with a null within the loop because getc stops when it reaches the EOF, the loop is broken...
It seems my code from the previous post is working!
Thanks a billion to all those who coached/helped/advised me on this matter. :)
Please comment if you think i can still further optimise my...
char *get_line(FILE *file)
{
FILE *fp = file;
char *buffer;
int ch, i=0;
unsigned int buffer_size = BUFFER_SIZE, new_buffer_size;
assert(buffer_size > 0);
sorry :
char *get_line(FILE *file)
{
FILE *fp = file;
char *buffer;
int ch, i=0;
unsigned int buffer_size = BUFFER_SIZE, new_buffer_size;