我需要有人为我解释二叉树

问题描述 投票:-4回答:2

编辑:找到编辑按钮,基本代码在https://github.com/unidef/quantum。如果你克隆并修复它,或者分叉它,它会很棒

这是一个快速粘贴

jons-MacBook-Pro:quantum jon$ cat */*
todo: makefile, srsly
cat: bin/tests: Is a directory
#pragma once
#include "quantum.h"

// tests

TEST temp;

// id system

double long  id;
#pragma once
#include "quantum.h"

extern FILE *filename;
extern FILE *extraFileName;
#pragma once
#include "sys.h"

#pragma once

// system macros

#define NEURAL_ARRAY          100
#define NEURAL_DIMENSION      20
#define NEURAL_DIRECTION      "up"

#define NEURAL_MALLOC         malloc(sizeof(NEURON))
#define NEURAL_MALLOC_BIG     malloc(sizeof( NEURON * 20 )

// system libraries

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <math.h>

// built in libraries

#include "types.h"
#include "doc.h"
#include "io.h"



// extra variables
#pragma once
#include "types.h"



typedef struct neural_node NODE;

typedef struct neural OPERATIONS;
typedef struct neural SQL;
typedef struct neural TEST;
typedef struct neural DOC;
typedef struct neural ERROR;
typedef struct neural NEURON;

typedef double long ID;
#pragma once

#include "sys.h"
#include "typedefs.h"


// data structures


struct neural {
  ID id;
  char *description;
  NODE *dimension[NEURAL_ARRAY][NEURAL_ARRAY][NEURAL_ARRAY];
} *N;

struct neural_node {
  ID id;
  DOC description;
  ERROR (*exception)(NODE,DOC);   // add SYS
  NODE *up;
  NODE *down;
  NODE *left;
  NODE *right;
} *NN;


#include "quantum.h"

// data operations

OPERATIONS arrange();
OPERATIONS delete();
OPERATIONS move();
OPERATIONS rearrange();
OPERATIONS query();


// internal sql database
SQL database();


// used for documentation purposes
DOC license();
DOC help();

void printq(char *msg, DOC *description){
  printf(msg, "%s");
}
#include "sys.h"
OPERATIONS arrange();
OPERATIONS delete();
OPERATIONS move();
OPERATIONS rearrange();
OPERATIONS query();



SQL database();



DOC license();
DOC help();
// types
// doc

// system variables

#define NEURAL_ARRAY 1000000
#define NEURAL_DIMENSION 20
#define NEURAL_DIRECTION "up"

// general variables

typedef struct _neural_node NODE;
typedef struct _neural OPERATIONS;
typedef struct _neural SQL;
typedef struct _neural TEST;
typedef struct _neural DOC;
typedef double long ID;

struct _neural {
  ID id;
  DOC description;
  NODE *dimension[NEURAL_ARRAY]; 
};
struct _neural_node {
  ID id;
  DOC description;
  NODE *up;
  NODE *down;
  NODE *left;
  NODE *right;
  NODE dimension[NEURAL_DIMENSION];
};


init:
    cc quantum.c -o quantum

tests:


trash:
    mv *~ trash
    mv lib/*~ trash
    mv bin/*~ trash
General Purpose Quantum Paralellization Library
by Unidef

Licensed by the BSD License

#include "lib/quantum.h"

// additional code


int main(){
  DOC INIT;
  return 0;
};  
#include "sys.h"

OPERATIONS arrange();
OPERATIONS delete();
OPERATIONS move();
OPERATIONS rearrange();
OPERATIONS query();



SQL database();



DOC license();
DOC help();
#pragma once
// system libraries

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <math.h>

// built in libraries

#include "types.h"
#include "doc.h"
#include "io.h"

// system variables

#define NEURAL_ARRAY 100
#define NEURAL_DIMENSION 20
#define NEURAL_DIRECTION "up"


#pragma once
#include "types.h"



typedef struct _neural_node NODE;

typedef struct _neural OPERATIONS;
typedef struct _neural SQL;
typedef struct _neural TEST;
typedef struct _neural DOC;
typedef struct _neural ERROR;
typedef struct _neural NEURON;

typedef double long ID;
#pragma once
#include "sys.h"
#include "types.h"
#include "typedefs.h"

// data structures


struct neural {
  ID id;
  char *description;
  NODE *dimension[NEURAL_ARRAY][NEURAL_ARRAY][NEURAL_ARRAY]; 
};

struct neural_node {
    ID id;
    DOC description;
    ERROR (*exception)(NODE);
    NODE *up;
    NODE *down;
    NODE *left;
    NODE *right;
   };


    jons-MacBook-Pro:quantum jon$ 

    ------

抱歉重复的代码,我有很多缓存的文件

基本上我有一个小数据库项目,我想配音作为神经/ ai技术,使用二维树到高维度,我只是混淆整个节点,指针,使用多少指针等事情

在我的脑海里,这是一棵二叉树。

#define X 100
struct NODE
{
    int id;
    NODE *movement[X];
};

    struct SQL 
    {
        char *description;
        NODE *next;
        NODE *prev;
        NODE *up;
        NODE *down;
    };


// usage

main()
{
    SQL *DOC[X];
    DOC[0] = (SQL*)(malloc(sizeof(SQL));
    DOC[0]->next->id = 0;
    DOC[0]->next->next->id=1;
}

// etc, didn't check it on a compiler

问题是它是段错误

c tree binary
2个回答
0
投票

是否需要使用C或二叉树?当我试图用神经网络做事时,我的多维数组的方法是使用扁平数组并用类似的东西计算索引

double & Tensor::operator[](std::initializer_list<int> list)
    {
        // TODO: insert return statement here
        vector<int> tuple(list.begin(), list.end());
        int dim = tuple[0];
        int lastDimensions = dimensions[0];
        for (int i = 1; i < tuple.size(); i++) {
            if (i > dimensions.size() - 1) 
            {
                break;
            }
            if (tuple[i] > dimensions[i]) throw exception("Dimension do not match");
            dim += tuple[i] * lastDimensions;
            lastDimensions *= dimensions[i];
        }
        return elements[dim];
    }

(全班可以在Tensor找到)

但也许我没有正确理解这个问题......


0
投票

您定义了一个指针数组,而不是一个结构数组。在使用它之前,必须使用指向SQL类型结构的指针进行初始化。或者像SQL DOC [X] = {0};一样创建一个数组

int main(int argc, char **argv)
{
        SQL *ptr = (SQL *) malloc(sizeof(SQL)*X);
        SQL DOC[X];

        if (!tmp)
                return 1;

        for (int i = 0; i < X; i++)
                DOC[i] = ptr+i;


        DOC[0]->next->id = 0;
        DOC[0]->next->next->id=1;
}
© www.soinside.com 2019 - 2024. All rights reserved.