6 programs in and I still am having issues with pointers. I'll attach the code I have below. Suffice to say I am having issues with pointers. I'm using CodeBlocks IDE. In line 9 of my doublerotateright I get a requet for a member error and in line 11 incompatible type argument. I believe I have declared the functions correctly, they needed to return the struct node. Thanks for any insight, I'm going to continue to google and dig till I find the errors of my way(or code).
<edit>
I've figured out a couple and changed the code to match. still having an issue with incompatible type argument in line 11 of doublerotateright, which is an error that affects doublerotateleft as well.
Code:
#include "prog6.h"
int main(int argc, char *argv[]){
FILE *infile;
infile = fopen("prog5.in", "r");
struct node *current;
current = NULL;
float num;
while(!feof(infile)){
fscanf(infile, "%f", &num);
insertnode(¤t, &num);
InOrderPrint(¤t);
}/*while(!feof(infile)){...*/
fclose(infile);
return 0;
} /*int main(int argc, char *argv[]){...*/
Code:
#include <stdio.h>
#include <stdlib.h>
struct node { /*Node Structure, each node has an floating point variable, an integer height, and a
pointer to the the left child, right child, and parent nodes*/
float *num;
struct node *left_child;
struct node *right_child;
struct node *parent;
int *node_height;
};
struct node insertnode(struct node **, float *);
struct node SingleRotateLeft(struct node **);
struct node DoubleRotateRight(struct node **);
struct node SingleRotateRight(struct node **);
struct node DoubleRotateRight(struct node **);
void InOrderPrint(struct node **);
Code:
#include "prog6.h"
struct node insertnode(struct node **current, float *num){
struct node *new = (struct node*)malloc(sizeof(struct node));
if(new != NULL){
(*new).num = num;
if(*current == NULL){
*current = new;
(**current).node_height = 0;
(**current).left_child = NULL;
(**current).right_child = NULL;
} /*if(*current == NULL){...*/
else if(num < (**current).num){
(**current).left_child = insertnode(**current.left_child, num);
if((**current).left_child.node_height - (**current).right_child.node_height == 2){
if( num > (**current).right_child.num )
*current = SingleRotateLeft(*current);
else
*current = DoubleRotateLeft(*current);
}/*if((**current).right_child.node_height - (**current).left_child.node_height == 2){...*/
else if(num > (**current).num){
(**current).right_child = insertnode(&(**current).right_child, num);
if((**current).right_child.node_height - (**current).left_child.node_height == 2){
if( num > (**current).right_child.num )
*current = SingleRotateWithRight(*current);
else
*current = DoubleRotateWithRight(*current);
}/*if((**current).right_child.node_height - (**current).left_child.node_height == 2){...*/
}/*else if(num > (**current).num){...*/
}/*else if(num < (**current).num){...*/
if((**current).left_child.node_height > (**current).right_child.node_height)
(**current).node_height = (**current).left_child.node_height + 1;
else
(**current).node_height = (**current).right_child.node_height + 1;
} /*if(new != NULL){...*/
} /*void insertnode(struct node **current, float *num){...*/
Code:
#include "prog6.h"
struct node DoubleRotateLeft(struct node **current){
(**current).left_child = SingleRotateRight(&(*current).left_child);
return SingleRotateLeft(current);
}/*struct node DoubleRotateLeft(struct node **current){...*/
Code:
#include "prog6.h"
struct node DoubleRotateRight(struct node **current){
(**current).right_child = SingleRotateLeft(&(*current).right_child);
return SingleRotateRight(current);
}/*struct node DoubleRotateRight(struct node **current){...*/
Code:
#include "prog6.h"
void InOrderPrint(struct node **current){
if((**current).left_child != NULL){
InOrderPrint(&(**current).left_child);
printf("%f, ", (**current).num);
if((**current).right_child != NULL){
InOrderPrint(&(**current).right_child);
}/*struct node DoubleRotateRight(struct node **current){...*/