What i was trying to do is, make a binary search tree, ask user for input 6 times, and then ask the user what number he would like to search for in the binary tree, if that number is found, store 1...
Type: Posts; User: Harith
What i was trying to do is, make a binary search tree, ask user for input 6 times, and then ask the user what number he would like to search for in the binary tree, if that number is found, store 1...
I entered the code bellow it, to see if the value exists in the tree:
follow = root;
int s;
printf("Enter a val: ");
scanf(" %d",&s);
int found = 0;
...
I tested it, but its not even waiting for me to enter value, number 3 is being displayed and then the program exists. i think compiler had problem, let me check again.
Hello guys,
I was working with binary search tree and came up with the solution:
#include<stdio.h>
#include<stdlib.h>
typedef struct data
{
c - Why does a space in my scanf statement make a difference? - Stack Overflow
Try this:
scanf(" %[^\n]");. Notice the space after opening quotes.
Okay, give me a hint which variables should I make local?
P.S I tried making all of them local and I had over 20 warnings.
/*
*Database for storing music cd.
*/
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<cs50.h>
#define MAX 200 //max characters a user can enter
Thanks man.
Did I mention I have shorten the program? Give me another reason to when to use global variables.
And I just noticed that last number is not being printed
That's it!! Thanks alot! But please explain to me why:
while(head != NULL) didn't worked?
But I am having the same result, what I want is with the same node I can move forth and back, is this possible?
Ya, I know this method, just wanted to try the next and previous method.
Why don't you use the function qsort?? qsort - C++ Reference
Okay I did as you said:
#include<stdio.h>
typedef struct node
{
int value;
struct node *next;
struct node *prev;
}node;
Ow, didn't even notice that mistake. Thanks man, and I will try and make the comments more useful. And fname is global because many functions are using it. :)
Hey,
/*
*Database for storing music cd.
*/
#include<stdio.h>
#define MAX 200 //max characters a user can enter
#include<stdio.h>
typedef struct node
{
int value;
struct node *next;
struct node *prev;
}node;
int main(void)
That's what I have done, haven't I?
Okay, I removed
head->next->prev = malloc(sizeof(node));, but still its not working.
Ya I changed so that head goes back where it started from; printing out numbers in reverse order, and then print the numbers again from start to end.
Hello,
I created a structure with two nodes in it, one that points to the next node and the other points to previous node:
#include<stdio.h>
typedef struct node
{
int ...
Thanks man for all the help. I am doing good now, but am stuck at deleting node problem:
#include<stdio.h>
typedef struct node
{
int x;
struct node *next;
}node;
Some other code I saw is really complex:
#include<stdlib.h>
#include<stdio.h>
struct list_el {
int val;
struct list_el * next;
};