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

时间:2019-02-14 16:40:31

标签: c tree binary

edit:找到“ edit”按钮,基本代码位于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$ 

    ------

对不起,重复的代码,我有很多缓存文件

基本上我有一个小型数据库项目,我想将其复制为一种神经/人工智能技术,该技术使用二叉树实现高维度,我只是对整个节点,指针,要使用多少个指针等感到困惑 >

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

#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

问题在于段错误

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分: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上找到整个课程)

但是也许我不正确地理解了这个问题...