# Binary Tree/Struct Problem

Page 1 of 1

## 3 Replies - 1046 Views - Last Post: 09 November 2012 - 08:23 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=299417&amp;s=78c5f1aa0f8fa3ef85934afe8a05e964&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 crapmyster

Reputation: 0
• Posts: 78
• Joined: 12-October 11

# Binary Tree/Struct Problem

Posted 09 November 2012 - 07:58 AM

Hello,

I'm just starting to get a binary tree on the go. I've got a problem already which I can't get my head round. I swear that I'm doing this correctly but not according to the compiler. I'm getting the error 'unknown type name 'node''./

#include <stdio.h>
#include <stdlib.h>
struct Node
{
int input;
Node * left
Node * right;
};

Is This A Good Question/Topic? 0

## Replies To: Binary Tree/Struct Problem

### #2 sepp2k

• D.I.C Lover

Reputation: 2610
• Posts: 4,163
• Joined: 21-June 11

## Re: Binary Tree/Struct Problem

Posted 09 November 2012 - 08:15 AM

In C (unlike C++) the name of a struct is not a valid type name by itself - it has to be prefaced with struct to become a type name.

So to declare a variable containing a Node pointer, write struct Node* varname;.

### #3 ivaylo9603

Reputation: 1
• Posts: 21
• Joined: 05-November 12

## Re: Binary Tree/Struct Problem

Posted 09 November 2012 - 08:19 AM

There is a syntax error in the posted code. It should either have a semi-colon after the declaration of pointer left, or both pointers- left and right should both be declared after the datatype in a single line, separated with commas as follows:
Node *left, *right;
//or
Node* left;
Node* right;

Sent from my GT-P3110

This post has been edited by ivaylo9603: 09 November 2012 - 08:23 AM

### #4 baavgai

• Dreaming Coder

Reputation: 7164
• Posts: 14,932
• Joined: 16-October 07

## Re: Binary Tree/Struct Problem

Posted 09 November 2012 - 08:23 AM

In C, use typedef to make life easier.

e.g.
typedef struct NodeStruct {
int input;
struct NodeStruct *left, *right;
} Node;

typedef struct {