Как сохранить видео файлы с помощью MySQL Workbench

Я пишу ответ, однако он не показывает всех детей. Код приведен ниже,

public class App {

    static class TreeNode {

        private int value;
        private ArrayList<TreeNode> children;

        public TreeNode(int nodeValue) {
            this.value = nodeValue;
            this.children = new ArrayList<TreeNode>();
        }

        public int getValue() {
            return this.value;
        }

        public void addChild(TreeNode child) {
            this.children.add(child);
        }

        public ArrayList<TreeNode> getChildren() {
            return this.children;
        }
    }


    public static TreeNode buildGraph(int[] T, int K) {

        final int N = T.length;

        TreeNode[] nodes = new TreeNode[N];

        for (int i = 0; i < N; i++) {
            nodes[i] = new TreeNode(i);
        }

        /*
            T[0] = 1
            T[1] = 2
            T[2] = 3
            T[3] = 3
            T[4] = 2
            T[5] = 1
            T[6] = 4

                 2 - 3
                / \
               1   4
              / |  |
             0  5  6
        * */

        TreeNode root = nodes[K];

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);

        boolean[] visited = new boolean[N];

        while (!queue.isEmpty()) {

            TreeNode node = queue.poll();
            int index = node.getValue();

            visited[index] = true;

            // T[3] = 3 is a leaf with no further connection to develop
            if (index == T[index]) {
                continue;
            }

            // 2 != 3 for the root node and we havent visited node 3 earlier
            if (index != T[index] && !visited[T[index]]) {

                node.addChild(nodes[T[index]]);
                queue.offer(nodes[T[index]]);
            }

            int left = 0, right = N - 1;

            while (left < index && right > index) {

                if (T[left] == index) {

                    node.addChild(nodes[left]);
                    queue.offer(nodes[left]);
                }

                if (T[right] == index) {

                    node.addChild(nodes[right]);
                    queue.offer(nodes[right]);
                }

                left++;
                right--;
            }
        }

        return root;
    }

    public static void main(String[] args) {

        int[] T = new int[7];

        T[0] = 1;
        T[1] = 2;
        T[2] = 3;
        T[3] = 3;
        T[4] = 2;
        T[5] = 1;
        T[6] = 4;

        TreeNode root = buildGraph(T, 2);

        System.out.println("The root = " + root.getValue());

        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);

        while(!queue.isEmpty()){

            TreeNode node = queue.poll();

            ArrayList<TreeNode> children = node.getChildren();

            for (int i = 0; i < children.size(); i++) {

                TreeNode child = children.get(i);
                queue.offer(child);

                System.out.println("Parent "+ node.getValue()+ " has children = "+ child.getValue());
            }
        }
    }
}

. В то время, когда я запускаю, я получаю вывод, например,

The root = 2
Parent 2 has children = 3
Parent 2 has children = 1
Parent 1 has children = 0

. Любой может помочь мне исправить, как я пропущу других детей ?

Обновить

Я пишу его на основе другого ответа, который кажется более простым.

public static TreeNode buildGraph1(int[] T, int K) {

        final int N = T.length;

        TreeNode[] nodes = new TreeNode[N];

        for (int i = 0; i < N; i++) {
            nodes[i] = new TreeNode(i);
        }

        /*
       T[children] = parent if the children != K

            T[0] = 1
            T[1] = 2
            T[2] = 3
            T[3] = 3
            T[4] = 2
            T[5] = 1
            T[6] = 4

                 2 - 3
                / \
               1   4
              / |  |
             0  5  6
        * */

        TreeNode root = nodes[K];
        int value = root.getValue();

        if (T[K] != K) {
            nodes[K].addChild(nodes[T[K]]);
        }

        for (int i = 0; i < T.length; ++i) {

            if (K == i) {
                continue;
            }

            if (T[i] != i) {
                nodes[T[i]].addChild(nodes[i]);
            }
        }

        return root;
    }

Вывод представлен ниже:

The root = 2
Parent 2 has children = 3
Parent 2 has children = 1
Parent 2 has children = 4




Parent 1 has children = 0
Parent 1 has children = 5


Parent 4 has children = 6
0
задан karel 17 February 2019 в 03:14
поделиться

1 ответ

Если вы уже знаете о формате BLOB, хранение видеофайлов не отличается от хранения любых других произвольных двоичных данных в базе данных. В зависимости от вашего языка вы должны сначала прочитать видеофайл в двоичном режиме (например, fread в PHP), а затем записать двоичный поток в поле BLOB в базу данных.

ОБНОВЛЕНИЕ : этот ответ больше не актуален после обнаружения, что вопрос скорее о MySQL Workbench, чем о MySQL в целом. Однако этот ответ может дать некоторую информацию, поэтому я еще не удалил его (пока).

0
ответ дан Cherusker 17 February 2019 в 03:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: