2017-07-14 11:24:11 +03:00
|
|
|
/* Includes structure for a node and a newNode() function which
|
2020-05-29 23:23:24 +03:00
|
|
|
can be used to create a new node in the tree.
|
2017-07-14 11:24:11 +03:00
|
|
|
It is assumed that the data in nodes will be an integer, though
|
|
|
|
function can be modified according to the data type, easily.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct node
|
|
|
|
{
|
|
|
|
struct node *leftNode;
|
|
|
|
int data;
|
|
|
|
struct node *rightNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct node *newNode(int data)
|
|
|
|
{
|
|
|
|
struct node *node = (struct node *)malloc(sizeof(struct node));
|
|
|
|
|
|
|
|
node->leftNode = NULL;
|
|
|
|
node->data = data;
|
|
|
|
node->rightNode = NULL;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
/* new node can be created here as :-
|
|
|
|
|
|
|
|
struct node *nameOfNode = newNode(data);
|
|
|
|
|
|
|
|
and tree can be formed by creating further nodes at
|
|
|
|
nameOfNode->leftNode and so on.
|
|
|
|
*/
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
return 0;
|
2017-07-14 11:24:11 +03:00
|
|
|
}
|