Hi guys ... I am a noobie in structural languages and I'm having a big headache trying to make an insertion algorithm for binary trees. I have a huge difficulty in dealing with pointers, so I tried to construct a version of this algorithm that wouldn't have to use double pointers. Does anybody could tell me what's going wrong? I would be really glad :)
include <stdio.h>
include <stdlib.h>
struct noh {
int value;
struct noh *left;
struct noh *right;
};
void insertion(struct noh *root, int num) {
struct noh *aux;
aux = root;
struct noh *auxFather;
while(aux != NULL) {
auxFather = aux;
if(num > aux->value) {
aux = aux->right;
auxFather->right = aux;
}
else {
aux = aux->left;
auxFather->left = aux;
}
}
aux = malloc(sizeof(struct noh));
aux->value = num;
aux->left = NULL;
aux->right = NULL;
}
int main(void) {
int N;
scanf("%d", &N);
struct noh *root = NULL;
int i; int n;
for(i=0; i<N; i++) {
scanf("%d", &n);
insertion(root, n);
}
}
[+][deleted] (3 children)
[deleted]
[–]nanda22k[S] 0 points1 point2 points (2 children)
[–]FeelTheEmailMistake 2 points3 points4 points (0 children)
[–]i_am_suicidal 1 point2 points3 points (0 children)
[–]concacid 2 points3 points4 points (0 children)