N
N
newmersedez2020-11-26 22:43:36
Data Structures
newmersedez, 2020-11-26 22:43:36

How to create an M-dimensional tree in SI?

Hello, I want to write an M-dimensional tree in SI so that one node has more than two children. I wrote the creation of the top of the tree, but I do not understand at all how to write the descendants. More precisely, I understand approximately, for this I created an array of pointers to the descendants and the number of these descendants, but I don’t understand how to represent this in the SI language.
Here is the code snippet I wrote:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct treeNode
{
    char                data;
    int                 childs;
    struct treeNode     **childPtr;
}treeNode;

void    insertNode(treeNode **treePtr, char data);

void    insertNode(treeNode **treePtr, char data)
{
    int i;

    if(*treePtr == NULL)
    {
        *treePtr = (treeNode *)malloc(sizeof(treeNode));
        (*treePtr)->data = data;
        (*treePtr)->childs = 0;
        (*treePtr)->childPtr = NULL;
    }
    else
    {
        //создать потомков
    }
    
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question