buggy_code stringlengths 11 625k | fixed_code stringlengths 17 625k | bug_type stringlengths 2 4.45k | language int64 0 8 | token_count int64 5 200k | change_count int64 0 100 |
|---|---|---|---|---|---|
class Node
def initialize(id)
@id = id
@left = nil
@right = nil
end
attr_accessor :id, :left, :right
end
def reconstruct_visit(node, index, lefts, rights)
direct_left = compare_by_preorder(lefts)
direct_right = compare_by_preorder(rights)
if direct_left >= 0 then
node.left = Node.new(dire... | class Node
def initialize(id)
@id = id
@left = nil
@right = nil
end
attr_accessor :id, :left, :right
end
def reconstruct_visit(node, index, lefts, rights)
direct_left = compare_by_preorder(lefts)
direct_right = compare_by_preorder(rights)
if direct_left >= 0 then
node.left = Node.new(dire... | [["-", 0, 652, 3, 4, 0, 742, 0, 475, 17, 389], ["-", 0, 652, 3, 4, 0, 742, 0, 475, 444, 22], ["+", 0, 652, 3, 4, 0, 742, 0, 475, 17, 757], ["+", 3, 4, 0, 742, 0, 475, 444, 748, 17, 33], ["+", 3, 4, 0, 742, 0, 475, 444, 748, 439, 612], ["+", 3, 4, 0, 742, 0, 475, 756, 738, 12, 612]] | 4 | 352 | 10 |
n = int(input())
pre = list(map(int, input().split()))
ino = list(map(int, input().split()))
d = []
root = pre[1]
pre = iter(pre).__next__
def dfs(l, r):
if l >= r:
return
c = pre()
m = ino.index(c)
dfs(l, m)
dfs(m+1, r)
d += [c]
dfs(0, len(ino))
print(*d)
| n = int(input())
pre = list(map(int, input().split()))
ino = list(map(int, input().split()))
d = []
root = pre[0]
pre = iter(pre).__next__
def dfs(l, r):
global d
if l >= r:
return
c = pre()
m = ino.index(c)
dfs(l, m)
dfs(m+1, r)
d += [c]
dfs(0, len(ino))
print(*d)
| [["-", 0, 656, 0, 1, 0, 662, 12, 206, 206, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 206, 206, 612], ["+", 0, 656, 0, 14, 8, 196, 0, 299, 0, 636], ["+", 0, 656, 0, 14, 8, 196, 0, 299, 0, 22]] | 5 | 120 | 4 |
#coding:UTF-8
def RoT(A,B,ans):
if A:
root=A[0]
rindex=B.index(root)
Aleft=A[1:rindex+1]
Aright=A[rindex+1:]
Bleft=B[:rindex]
Bright=B[rindex:]
RoT(Aleft,Bleft,ans)
RoT(Aright,Bright,ans)
ans.append(root)
if __name__=="__ma... | #coding:UTF-8
def RoT(A,B,ans):
if A:
root=A[0]
rindex=B.index(root)
Aleft=A[1:rindex+1]
Aright=A[rindex+1:]
Bleft=B[:rindex]
Bright=B[rindex+1:]
RoT(Aleft,Bleft,ans)
RoT(Aright,Bright,ans)
ans.append(root)
if __name__=="__... | [["+", 0, 662, 12, 206, 206, 663, 0, 657, 17, 72], ["+", 0, 662, 12, 206, 206, 663, 0, 657, 12, 612]] | 5 | 145 | 2 |
#Reconstruction of the Tree
n = int(input())
pre = list(map(int,input().split()))
ino = list(map(int,input().split()))
post=[]
i = -1
def recaonstruction(l, r):
global i
if l >= r:
return
i += 1
c = pre[i]
m = ino.index(c)
reconstruction(l, m)
reconstruction(m+1, r)
post.append(... | n = int(input())
pre = list(map(int,input().split()))
ino = list(map(int,input().split()))
post=[]
i = -1
def reconstruction(l, r):
global i
if l >= r:
return
i += 1
c = pre[i]
m = ino.index(c)
reconstruction(l, m)
reconstruction(m+1, r)
post.append(c)
reconstruction(0, n)
print... | [["-", 36, 36, 36, 36, 0, 656, 0, 14, 141, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 14, 141, 22]] | 5 | 126 | 2 |
def getPostorder(preorder, inorder):
if not preorder:
return []
postorder = []
root = preorder[0]
rootIndex = inorder.index(root)
postorder.extend(getPostorder(preorder[1:rootIndex + 1], inorder[:rootIndex]))
postorder.extend(getPostorder(preorder[rootIndex + 1:], inorder[rootIndex + 1:... | def getPostorder(preorder, inorder):
if not preorder:
return []
postorder = []
root = preorder[0]
rootIndex = inorder.index(root)
postorder.extend(getPostorder(preorder[1:rootIndex + 1], inorder[:rootIndex]))
postorder.extend(getPostorder(preorder[rootIndex + 1:], inorder[rootIndex + 1:... | [["+", 0, 652, 3, 4, 0, 652, 63, 661, 0, 48]] | 5 | 144 | 1 |
#include <cstdint>
#include <iostream>
using namespace std;
template <typename T> class BinTree {
private:
struct Node {
T val;
Node *parent;
Node *left;
Node *right;
};
Node *root;
void inner_print_inorder(Node *x) {
if (x == NULL)
return;
inner_print_inorder(x->left);
co... | #include <cstdint>
#include <iostream>
using namespace std;
template <typename T> class BinTree {
private:
struct Node {
T val;
Node *parent;
Node *left;
Node *right;
};
Node *root;
void inner_print_inorder(Node *x) {
if (x == NULL)
return;
inner_print_inorder(x->left);
co... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 397 | 4 |
/*
* Problem Description: Binary Search Tree I
* Category: Binary Search Trees
* Author: Khan
* Date: 21th October, 2017
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *r, *l, *p;
};
Node *root, *NIL;
void Insert(int k) {
No... | /*
* Problem Description: Binary Search Tree I
* Category: Binary Search Trees
* Author: Khan
* Date: 21th October, 2017
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *r, *l, *p;
};
Node *root, *NIL;
void Insert(int k) {
No... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 374 | 4 |
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;
while (x... | #include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;
while (x... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 370 | 4 |
#include <cstdio>
#include <iostream>
#include <memory>
using namespace std;
struct Node {
int key;
Node *parent;
Node *left;
Node *right;
Node(int key = -1)
: key(key), parent(nullptr), left(nullptr), right(nullptr){};
};
struct Tree {
Node *root;
Tree() : root(nullptr){};
};
static void inse... | #include <cstdio>
#include <iostream>
#include <memory>
using namespace std;
struct Node {
int key;
Node *parent;
Node *left;
Node *right;
Node(int key = -1)
: key(key), parent(nullptr), left(nullptr), right(nullptr){};
};
struct Tree {
Node *root;
Tree() : root(nullptr){};
};
static void inse... | [["-", 75, 76, 0, 9, 0, 1, 0, 2, 63, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 2, 63, 22]] | 1 | 439 | 4 |
#include <iostream>
#include <stdio.h>
using namespace std;
struct Node {
int key;
Node *parent;
Node *left;
Node *right;
};
struct Node *NIL, *root;
void init() { root = NIL; }
void insert(Node *z) {
struct Node *y = NIL; // xの親
struct Node *x = root;
while (x != NIL) {
y = x;
if (z->key < x... | #include <iostream>
#include <stdio.h>
using namespace std;
struct Node {
int key;
Node *parent;
Node *left;
Node *right;
};
struct Node *NIL, *root;
void init() { root = NIL; }
void insert(Node *z) {
struct Node *y = NIL; // xの親
struct Node *x = root;
while (x != NIL) {
y = x;
if (z->key < x... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 1 | 415 | 2 |
#include <iostream>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;
while (x != NIL) {
y = x;
if (z->ke... | #include <iostream>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->right = NIL;
while (x != NIL) {
y = x;
if (z->ke... | [["-", 0, 1, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 0, 1, 0, 2, 3, 4, 0, 118, 119, 120]] | 1 | 346 | 4 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <st... | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <st... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 398 | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *NIL;
struct BST {
Node *root;
BST() { root = NIL; }
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->... | #include <bits/stdc++.h>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *NIL;
struct BST {
Node *root;
BST() { root = NIL; }
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z = (Node *)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 351 | 4 |
#include <cstdlib>
#include <iostream>
using namespace std;
struct tree {
tree *left;
tree *right;
tree *parent;
int val;
};
void printInorder(tree *root) {
if (root == NULL)
return;
cout << " " << root->val;
printInorder(root->left);
printInorder(root->right);
return;
}
void printPreorder(tree ... | #include <cstdlib>
#include <iostream>
using namespace std;
struct tree {
tree *left;
tree *right;
tree *parent;
int val;
};
void printInorder(tree *root) {
if (root == NULL)
return;
cout << " " << root->val;
printInorder(root->left);
printInorder(root->right);
return;
}
void printPreorder(tree ... | [["-", 75, 76, 0, 9, 0, 1, 0, 2, 63, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 2, 63, 22]] | 1 | 378 | 4 |
def reconstruct(pre, in_):
if not pre:
return -1
root = pre[0]
i = in_.index(root)
tree[root] = (reconstruct(pre[1 : i+1], in_[:i]), reconstruct(pre[i+1:], in_[i+1:]))
return root
def postorder(i):
if i == -1:
return
l, r = tree[i]
for v in postorder(l):
yield v
... | def reconstruct(pre, in_):
if not pre:
return -1
root = pre[0]
i = in_.index(root)
tree[root] = (reconstruct(pre[1 : i+1], in_[:i]), reconstruct(pre[i+1:], in_[i+1:]))
return root
def postorder(i):
if i == -1:
return
l, r = tree[i]
for v in postorder(l):
yield v
... | [["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24]] | 5 | 194 | 4 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
class Main {
static class BinarySearch {
static Node root = null;
public void binarysearch(InputReader ir) {
... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
class Main {
static class BinarySearch {
static Node root = null;
public void binarysearch(InputReader ir) {
... | [["-", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22]] | 3 | 592 | 4 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
typedef struct node *NodePointer;
NodePointer root;
NodePointer nil;
void insert(int k) {
NodePointer y, x, z;
y = nil;
x = root;
z = (NodePointer)malloc(s... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
typedef struct node *NodePointer;
NodePointer root;
NodePointer nil;
void insert(int k) {
NodePointer y, x, z;
y = nil;
x = root;
z = (NodePointer)malloc(s... | [["-", 0, 14, 8, 9, 0, 43, 49, 84, 0, 48], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 0, 70], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 0, 73]] | 0 | 379 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | [["-", 0, 57, 64, 1, 0, 11, 12, 118, 119, 120], ["+", 0, 57, 64, 1, 0, 11, 12, 118, 119, 120]] | 0 | 756 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node {
int key;
struct node *r, *l, *par;
} Node;
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->l = NIL;
z->r = NIL;
while (x != NIL) {
y... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node {
int key;
struct node *r, *l, *par;
} Node;
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = (Node *)malloc(sizeof(Node));
z->key = k;
z->l = NIL;
z->r = NIL;
while (x != NIL) {
y... | [["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]] | 0 | 387 | 4 |
#include <stdio.h>
#include <stdlib.h>
#define N_MAX 500001
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
typedef struct node *Node;
Node root = NULL;
void insert(int k) {
Node y = NULL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
... | #include <stdio.h>
#include <stdlib.h>
#define N_MAX 500001
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
typedef struct node *Node;
Node root = NULL;
void insert(int k) {
Node y = NULL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
... | [["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]] | 0 | 452 | 4 |
#include <stdio.h>
#include <string.h>
#define STR_MAX 100
#define MAX_NODE 500001
// ノード型定義
typedef struct _NODE {
int key;
struct _NODE *right;
struct _NODE *left;
} NODE;
// ノード用RAM管理
NODE node_pool[MAX_NODE];
int node_cnt;
NODE *make_node(int key);
// ツリー操作
NODE *insert_tree(NODE *root, int k);
void print... | #include <stdio.h>
#include <string.h>
#define STR_MAX 100
#define MAX_NODE 500001
// ノード型定義
typedef struct _NODE {
int key;
struct _NODE *right;
struct _NODE *left;
} NODE;
// ノード用RAM管理
NODE node_pool[MAX_NODE];
int node_cnt;
NODE *make_node(int key);
// ツリー操作
NODE *insert_tree(NODE *root, int k);
void print... | [["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]] | 0 | 523 | 2 |
#include <stdio.h>
#define STR_MAX 100
#define MAX_NODE 500001
typedef struct _NODE {
int key;
struct _NODE *right;
struct _NODE *left;
} NODE;
NODE node_pool[MAX_NODE];
int node_cnt;
NODE *root;
void insert_tree(NODE **root, int k);
void print_tree(NODE *root);
void print_tree_inorder(NODE *node);
void print... | #include <stdio.h>
#define STR_MAX 100
#define MAX_NODE 500001
typedef struct _NODE {
int key;
struct _NODE *right;
struct _NODE *left;
} NODE;
NODE node_pool[MAX_NODE];
int node_cnt;
NODE *root;
void insert_tree(NODE **root, int k);
void print_tree(NODE *root);
void print_tree_inorder(NODE *node);
void print... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 0 | 446 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
void insert(int k);
typedef struct node *Node;
void inorder(Node u);
void preorder(Node u);
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
void insert(int k);
typedef struct node *Node;
void inorder(Node u);
void preorder(Node u);
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 427 | 4 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
struct Node *root, *NIL;
void insert(int k);
void inorder(struct Node *n);
void preorder(struct Node *n);
int main() {
int i, n, s;
char code[10];
scanf("%... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
struct Node *root, *NIL;
void insert(int k);
void inorder(struct Node *n);
void preorder(struct Node *n);
int main() {
int i, n, s;
char code[10];
scanf("%... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 403 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | [["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46]] | 0 | 374 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *p;
struct node *left;
struct node *right;
};
typedef struct node *Node;
Node root, NIL;
int max;
void insert(int k) {
int T;
Node x = root;
Node y = NIL;
Node z;
z = malloc(sizeof(struct node));
z->key... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *p;
struct node *left;
struct node *right;
};
typedef struct node *Node;
Node root, NIL;
int max;
void insert(int k) {
int T;
Node x = root;
Node y = NIL;
Node z;
z = malloc(sizeof(struct node));
z->key... | [["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 28, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 17, 143], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120]] | 0 | 393 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | [["-", 0, 9, 0, 1, 0, 11, 12, 118, 119, 120], ["+", 0, 9, 0, 1, 0, 11, 12, 118, 119, 120]] | 0 | 779 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
int key;
struct node *parent;
struct node *right;
struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
void Preorder(Node);
void Inorder(Node);
int main() {
int n, i, key;
char S[7];
scanf("%d", &n);
for (i = ... | #include <stdio.h>
#include <stdlib.h>
struct node {
int key;
struct node *parent;
struct node *right;
struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
void Preorder(Node);
void Inorder(Node);
int main() {
int n, i, key;
char S[7];
scanf("%d", &n);
for (i = ... | [["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]] | 0 | 496 | 2 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z ... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z ... | [["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13]] | 0 | 542 | 8 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {}
Node treeSearch(Node u, int k) {}
Node treeSuccessor(Node x) {}
void treeDelete(Node z) {
Node y... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {}
Node treeSearch(Node u, int k) {}
Node treeSuccessor(Node x) {}
void treeDelete(Node z) {
Node y... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 502 | 4 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL -1
struct node {
int key;
struct node *parent, *left, *right;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
int main() {
int n, k, i;
char a[6];
scanf("%d", &n);
for (i = 0; i <... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL NULL
struct node {
int key;
struct node *parent, *left, *right;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
int main() {
int n, k, i;
char a[6];
scanf("%d", &n);
for (i = 0; i... | [["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]] | 0 | 399 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
}
return x;
}
Node treeSearch(Node u, int k) {
whil... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
}
return x;
}
Node treeSearch(Node u, int k) {
whil... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 807 | 4 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
Node treeMinimum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void insert(int);
void inor... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
Node treeMinimum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void insert(int);
void inor... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 0 | 678 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | [["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]] | 0 | 384 | 4 |
from sys import stdin
class Node(object):
def __init__(self, parent=None, left=None, right=None):
self.parent = parent
self.left = left
self.right = right
def print_nodes(nodes, n):
A = []
B = []
C = []
def walk_tree(nodes, u):
if u == -1:
return
... | from sys import stdin
class Node(object):
def __init__(self, parent=None, left=None, right=None):
self.parent = parent
self.left = left
self.right = right
def print_nodes(nodes, n):
A = []
B = []
C = []
def walk_tree(nodes, u):
if u == -1:
return
... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]] | 5 | 367 | 2 |
from collections import namedtuple
class TreeWalk:
def __init__(self, t):
self.t = t
def preParse(self, u):
if u == -1:
return
print(" ", str(u), end = "")
self.preParse(self.t[u].l)
self.preParse(self.t[u].r)
def inParse(self, u):
if u == -1:
... | from collections import namedtuple
class TreeWalk:
def __init__(self, t):
self.t = t
def preParse(self, u):
if u == -1:
return
print("", str(u), end = "")
self.preParse(self.t[u].l)
self.preParse(self.t[u].r)
def inParse(self, u):
if u == -1:
... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 8, 196, 0, 1, 0, 652, 63, 319, 319, 22], ["+", 8, 196, 0, 1, 0, 652, 63, 319, 319, 22]] | 5 | 429 | 7 |
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C&lang=jp
import time
def preorder(binary_tree, target_index, result):
result.append(target_index)
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
preorder(binary_tree, ... | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C&lang=jp
import time
def preorder(binary_tree, target_index, result):
result.append(target_index)
left = binary_tree[target_index]["left"]
right = binary_tree[target_index]["right"]
if not left == -1:
preorder(binary_tree, ... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 0, 652, 3, 4, 0, 557, 0, 6, 0, 44], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 557, 0, 6, 0, 44]] | 5 | 457 | 2 |
import sys
def main():
n = eval(input())
tree = MyTree(n)
for i in range(n):
id_cn = list(map(int,input().split()))
id_node = id_cn.pop(0)
tree.add(id_node,None,id_cn)
tree.search_children()
tree.set_depth_height(tree.nodes[tree.id_root],0)
print("Prorder"... | import sys
def main():
n = eval(input())
tree = MyTree(n)
for i in range(n):
id_cn = list(map(int,input().split()))
id_node = id_cn.pop(0)
tree.add(id_node,None,id_cn)
tree.search_children()
tree.set_depth_height(tree.nodes[tree.id_root],0)
print("Preorder... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655]] | 5 | 800 | 7 |
n = int(input())
tree = [0] * n
root = set(range(n))
for i in range(n):
node_id, left, right = map(int, input().split())
tree[node_id] = (left, right)
root -= {left, right}
root_node = root.pop()
def preorder(i):
if i == -1:
return
(left, right) = tree[i]
yield i
yield from preorde... | n = int(input())
tree = [0] * n
root = set(range(n))
for i in range(n):
node_id, left, right = map(int, input().split())
tree[node_id] = (left, right)
root -= {left, right}
root_node = root.pop()
def preorder(i):
if i == -1:
return
(left, right) = tree[i]
yield i
yield from preorde... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 0, 652, 3, 4, 0, 557, 0, 6, 0, 44], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 557, 0, 6, 0, 44]] | 5 | 245 | 6 |
N = int(input())
tree = [None for _ in range(N)]
root = set(range(N))
for i in range(N):
i, l, r = map(int,input().split())
tree[i] = (l, r)
root -= {l, r}
root_node = root.pop()
def preorder(i):
if i == -1:
return
(l, r) = tree[i]
print(" {}".format(i), end = "")
preorder(l)
... | N = int(input())
tree = [None for _ in range(N)]
root = set(range(N))
for i in range(N):
i, l, r = map(int,input().split())
tree[i] = (l, r)
root -= {l, r}
root_node = root.pop()
def preorder(i):
if i == -1:
return
(l, r) = tree[i]
print(" {}".format(i), end = "")
preorder(l)
... | [["-", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22]] | 5 | 259 | 4 |
# -*- coding: utf-8 -*-
"""
Created on Sat May 19 19:34:44 2018
ALDS1_7_B
@author: maezawa
"""
n = int(input())
parent = [-1 for _ in range(n)]
left = [-1 for _ in range(n)]
right = [-1 for _ in range(n)]
height = [None for _ in range(n)]
depth = [None for _ in range(n)]
def set_parent():
global parent
for i... | # -*- coding: utf-8 -*-
"""
Created on Sat May 19 19:34:44 2018
ALDS1_7_B
@author: maezawa
"""
n = int(input())
parent = [-1 for _ in range(n)]
left = [-1 for _ in range(n)]
right = [-1 for _ in range(n)]
height = [None for _ in range(n)]
depth = [None for _ in range(n)]
def set_parent():
global parent
for i... | [["-", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22]] | 5 | 620 | 2 |
n = int(input())
tree = [[-1, -1, True] for i in range(n)]
for i in range(n):
id, left, right = map(int, input().split())
if left != -1:
tree[id][0] = left
tree[left][2] = False
if right != -1:
tree[id][1] = right
tree[right][2] = False
def preoder(id):
if id == -1:
... | n = int(input())
tree = [[-1, -1, True] for i in range(n)]
for i in range(n):
id, left, right = map(int, input().split())
if left != -1:
tree[id][0] = left
tree[left][2] = False
if right != -1:
tree[id][1] = right
tree[right][2] = False
def preoder(id):
if id == -1:
... | [["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 654], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 655]] | 5 | 313 | 7 |
Parent = 0
Lchild = 1
Rchild = 2
def childs(n):
return node[n][Lchild:Rchild+1]
def preorder(n):
if n == -1: return []
c1, c2 = childs(n)
return [n] + preorder(c1) + preorder(c2)
def inorder(n):
if n == -1: return []
c1, c2 = childs(n)
return inorder(c1) + [n] +inorder(c2)
def postorder(... | Parent = 0
Lchild = 1
Rchild = 2
def childs(n):
return node[n][Lchild:Rchild+1]
def preorder(n):
if n == -1: return []
c1, c2 = childs(n)
return [n] + preorder(c1) + preorder(c2)
def inorder(n):
if n == -1: return []
c1, c2 = childs(n)
return inorder(c1) + [n] +inorder(c2)
def postorder(... | [["-", 0, 57, 15, 666, 0, 206, 51, 206, 206, 22], ["+", 0, 57, 15, 666, 0, 206, 51, 206, 206, 22]] | 5 | 355 | 2 |
#include <stdio.h>
#define POINT 41
int P[POINT], I[POINT], Po[POINT];
int n, now = 0, s = 0;
void Rec(int, int);
void Rec(int l, int r) {
int c, m;
// printf("0");
if (l >= r) {
return;
}
c = P[now++];
m = Find(c);
Rec(l, m);
// printf("1");
Rec(m + 1, r);
// printf("2");
Po[s++] =... | #include <stdio.h>
#define POINT 41
int P[POINT], I[POINT], Po[POINT];
int n, now = 0, s = 0;
void Rec(int, int);
void Rec(int l, int r) {
int c, m;
if (l >= r) {
return;
}
c = P[now++];
m = Find(c);
Rec(l, m);
Rec(m + 1, r);
Po[s++] = c;
}
int Find(int c) {
int i;
//接点番号が一致したIndexを返す
fo... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 284 | 2 |
#include <stdio.h>
#define N 100
int n, pos, count = 0;
int pre[N], in[N], post[N];
int find(int in[n], int root) {
int i;
for (i = 0; i < n; i++) {
if (in[i] == root)
return i;
}
return in[n - 1];
}
void rec(int l, int r) {
int root, m;
if (l >= r)
return;
root = pre[pos++];
m = find(i... | #include <stdio.h>
#define N 100
int n, pos, count = 0;
int pre[N], in[N], post[N];
int find(int in[n], int root) {
int i;
for (i = 0; i < n; i++) {
if (in[i] == root)
return i;
}
return in[n - 1];
}
void rec(int l, int r) {
int root, m;
if (l >= r)
return;
root = pre[pos++];
m = find(i... | [["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]] | 0 | 304 | 2 |
#include <stdio.h>
#define MAX 40
int n, pos = 0;
int cout = 0;
int Pre[MAX], In[MAX], Ans[MAX];
int distance(int start, int key) {
int i, count = 1;
for (i = start; i < MAX; i++) {
if (In[i] != key)
count++;
else
break;
}
return count;
}
int solve(int l, int r) {
int root, d;
if (l ... | #include <stdio.h>
#define MAX 40
int n, pos = 0;
int cout = 0;
int Pre[MAX], In[MAX], Ans[MAX];
int distance(int start, int key) {
int i, count = 0;
for (i = start; i < MAX; i++) {
if (In[i] != key)
count++;
else
break;
}
return count;
}
int solve(int l, int r) {
int root, d;
if (l ... | [["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]] | 0 | 305 | 2 |
#include <stdio.h>
#include <stdlib.h>
int preOrder[40], inOrder[40];
void solve(int x, int y) {
int i;
static int p = 0;
if (x > y)
return;
if (x == y) {
if (inOrder[x] == preOrder[0])
printf("%d", inOrder[x]);
else
printf("%d ", inOrder[x]);
p++;
return;
}
int a = preOrde... | #include <stdio.h>
#include <stdlib.h>
int preOrder[40], inOrder[40];
void solve(int x, int y) {
int i;
static int p = 0;
if (x > y)
return;
if (x == y) {
if (inOrder[x] == preOrder[0])
printf("%d", inOrder[x]);
else
printf("%d ", inOrder[x]);
p++;
return;
}
int a = preOrde... | [["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 22], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 22], ["+", 0, 57, 64, 1, 0, 2, 3, 4, 0, 22], ["-", 75, 76, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 75, 76, 0, 1, 0, 2, 3, 4, 0, 22]] | 0 | 268 | 6 |
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq) {
int nMaxSiz;
cin >> nMaxSiz;
rvnPodr.resize(nMaxSiz);
rvnIodrSeq.resize(nMaxSiz + 1);
for (int i = 0; i < nMaxSiz; i++)
cin >> rvnPodr[i];
int nNode;
for (int i = 1; i < nMaxSiz... | #include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq) {
int nMaxSiz;
cin >> nMaxSiz;
rvnPodr.resize(nMaxSiz + 1);
rvnIodrSeq.resize(nMaxSiz + 1);
for (int i = 1; i < nMaxSiz + 1; i++)
cin >> rvnPodr[i];
int nNode;
for (int i = 1; i <... | [["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43... | 1 | 263 | 8 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
int flag;
void search(Node u, int k) {
if (k == u->key) {
printf("\nYes");
flag++;
}
if (k < u->key) {
if (u->l... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
int flag;
void search(Node u, int k) {
if (k == u->key) {
printf("yes\n");
flag++;
}
if (k < u->key) {
if (u->l... | [["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 526 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->right != NIL)
x = x->left;
return x;
}
Node treeSearch(Node x, int k) {
while (x ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root = NIL;
Node treeMinimum(Node x) {
while (x->right != NIL)
x = x->left;
return x;
}
Node treeSearch(Node x, int k) {
whi... | [["+", 36, 36, 0, 30, 0, 43, 49, 50, 0, 32], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 22], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]] | 0 | 726 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
}
return x;
}
Node treeSearch(Node u, int k) {
whi... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
}
return x;
}
Node treeSearch(Node u, int k) {
whi... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 767 | 1 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
Node tS(Node, int);
void ins(int);
void pre(Node);
void ino(Node);
int main() {
int n, i, a;
char c[20];
scanf("%d", &n... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
Node tS(Node, int);
void ins(int);
void pre(Node);
void ino(Node);
int main() {
int n, i, a;
char c[20];
scanf("%d", &n... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 538 | 1 |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, N) for (ll i = 0; i < N; ++i)
struct Node {
Node(){};
~Node() {
delete left;
delete right;
};
long long key;
Node *parent;
Node *left;
Node *right;
};
// root node is not nullptr
voi... | #include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, N) for (ll i = 0; i < N; ++i)
struct Node {
Node(){};
~Node() {
delete left;
delete right;
};
long long key;
Node *parent;
Node *left;
Node *right;
};
// root node is not nullptr
voi... | [["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]] | 1 | 571 | 4 |
#include <iostream>
#include <memory>
#include <string>
namespace BinarySearchTree {
using namespace std;
constexpr int nullNum = -1;
class Node {
public:
Node(int k, shared_ptr<Node> p, shared_ptr<Node> l, shared_ptr<Node> r)
: key(k), parent(p), left(l), right(r) {}
Node(int k) : key(k), parent(nullptr),... | #include <iostream>
#include <memory>
#include <string>
namespace BinarySearchTree {
using namespace std;
constexpr int nullNum = -1;
class Node {
public:
Node(int k, shared_ptr<Node> p, shared_ptr<Node> l, shared_ptr<Node> r)
: key(k), parent(p), left(l), right(r) {}
Node(int k) : key(k), parent(nullptr),... | [["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 35], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 49, 53, 54, 55, 0, 56, 49, 352, 0, 67], ["-", 75, 76, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60], ["-... | 1 | 787 | 9 |
class Tree
attr_accessor :id,:parent,:children
def initialize(id)
@id=id
@parent=-1
@children=[nil,nil]
end
def preorder
print " #{id}"
children[0].preorder if children[0]
children[1].preorder if children[1]
end
def inorder
children[0].inorder if children[0]
print " #{id}"
... | class Tree
attr_accessor :id,:parent,:children
def initialize(id)
@id=id
@parent=-1
@children=[nil,nil]
end
def preorder
print " #{id}"
children[0].preorder if children[0]
children[1].preorder if children[1]
end
def inorder
children[0].inorder if children[0]
print " #{id}"
... | [["-", 64, 749, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 64, 749, 0, 652, 3, 4, 0, 557, 0, 6], ["-", 75, 95, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 75, 95, 0, 652, 3, 4, 0, 557, 0, 6]] | 4 | 284 | 4 |
from io import StringIO
class BinaryTree:
class Node:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
self.parent = None
def __init__(self):
self.root = None
self.output = StringIO()
def insert(self, key)... | from io import StringIO
class BinaryTree:
class Node:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
self.parent = None
def __init__(self):
self.root = None
self.output = StringIO()
def insert(self, key)... | [["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]] | 5 | 528 | 3 |
import sys
import time
class Node:
def __init__(self, key):
self.key = key
self.parent = None
self.left = None
self.right = None
def insert(z):
global root
y = None
x = root
while x is not None:
y = x
if z.key < x.key:
x = x.left
... | import sys
import time
class Node:
def __init__(self, key):
self.key = key
self.parent = None
self.left = None
self.right = None
def insert(z):
global root
y = None
x = root
while x is not None:
y = x
if z.key < x.key:
x = x.left
... | [["-", 8, 196, 0, 57, 75, 665, 15, 666, 667, 18], ["+", 8, 196, 0, 57, 75, 665, 15, 666, 667, 47]] | 5 | 392 | 2 |
class Tree:
def __init__(self, orders):
self.root = None
for order in orders:
if len(order) == 1:
self.inorder_print()
self.preorder_print()
else:
if len(order[0]) == 4:
self.find(int(order[1]))
... | class Tree:
def __init__(self, orders):
self.root = None
for order in orders:
if len(order) == 1:
self.inorder_print()
self.preorder_print()
else:
if len(order[0]) == 4:
self.find(int(order[1]))
... | [["-", 0, 656, 0, 682, 8, 196, 0, 14, 141, 22], ["+", 0, 656, 0, 682, 8, 196, 0, 14, 141, 22]] | 5 | 450 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node {
int id;
struct node *parent;
struct node *child[2];
} * nodePointer;
nodePointer root;
nodePointer make1node(int);
void insert(nodePointer);
int find(nodePointer, int);
void preorderWalk(nodePointer);
void inorderWalk(nodePointer);
i... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node {
int id;
struct node *parent;
struct node *child[2];
} * nodePointer;
nodePointer root;
nodePointer make1node(int);
void insert(nodePointer);
int find(nodePointer, int);
void preorderWalk(nodePointer);
void inorderWalk(nodePointer);
i... | [["-", 64, 37, 0, 2, 3, 4, 0, 69, 71, 13], ["+", 64, 37, 0, 2, 3, 4, 0, 69, 71, 13], ["-", 8, 9, 0, 57, 64, 37, 0, 23, 0, 24], ["-", 64, 37, 0, 23, 0, 2, 3, 4, 0, 25]] | 0 | 631 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 756 | 1 |
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->right != NIL) {
x = x->right;
}
return x;
}
Node treeMaximum(Node x) {
while (x->right != NIL) {
... | #include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->right != NIL) {
x = x->right;
}
return x;
}
Node treeMaximum(Node x) {
while (x->right != NIL) {
... | [["-", 0, 37, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 0, 37, 0, 2, 3, 4, 0, 118, 119, 120]] | 0 | 659 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *r;
struct node *l;
struct node *p;
int key;
};
typedef struct node *Node;
Node root;
Node treeSearch(Node u, int k) {
while (u != NULL && k != u->key) {
if (k < u->key)
u = u->l;
else
u = u->r;
}
return u;
}
void ins... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *r;
struct node *l;
struct node *p;
int key;
};
typedef struct node *Node;
Node root;
Node find(Node u, int k) {
while (u != NULL && k != u->key) {
if (k < u->key)
u = u->l;
else
u = u->r;
}
return u;
}
void insert(in... | [["-", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["-", 8, 9, 0, 57, 64, 9, 0, 43, 0, 35], ["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 43, 49, 50, 0, 32], ["+", 64, 9, 0, 43, 49, 50, 51, 2, 63, 22]] | 0 | 482 | 6 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
struct Node *root, *NIL;
void insert(int k);
void inorder(struct Node *n);
void preorder(struct Node *n);
struct Node *find(struct Node *n, int i);
int main() {
... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
struct Node *root, *NIL;
void insert(int k);
void inorder(struct Node *n);
void preorder(struct Node *n);
struct Node *find(struct Node *n, int i);
int main() {
... | [["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 530 | 2 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = N... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = N... | [["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22]] | 0 | 484 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node, int);
int main() {
int i, m, *s, x, n;
char com[20];
scanf(... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root;
void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node, int);
int main() {
int i, m, *s, x, n;
char com[20];
scanf(... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 503 | 1 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *r, *l, *p;
int key;
};
typedef struct node *Node;
Node root, NIL;
Node treeSearch(Node u, int k) {
while ((u != NIL) && (k != u->key)) {
if (k < u->key)
u = u->l;
else
u = u->r;
}
return u;
}
void insert(int k) {
int ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *r, *l, *p;
int key;
};
typedef struct node *Node;
Node root, NIL;
Node treeSearch(Node u, int k) {
while ((u != NIL) && (k != u->key)) {
if (k < u->key)
u = u->l;
else
u = u->r;
}
return u;
}
void insert(int k) {
int ... | [["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22]] | 0 | 480 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root, NIL;
int max;
Node treeSearch(Node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->ri... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root, NIL;
int max;
Node treeSearch(Node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->ri... | [["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32]] | 0 | 493 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
typedef struct Node *node;
#define NIL NULL
node root;
node find(node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->right... | #include <stdio.h>
#include <stdlib.h>
struct Node {
int key;
struct Node *right;
struct Node *left;
struct Node *parent;
};
typedef struct Node *node;
#define NIL NULL
node root;
node find(node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->right... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 486 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeMaximum(Node x) {
while (x->right ... | [["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 106], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98]] | 0 | 828 | 2 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *p;
struct node *r;
struct node *l;
int key;
};
typedef struct node *Node;
Node root;
void insert(int v) {
Node y = NIL;
Node x = root;
Node c;
c = malloc(sizeof(struct node));
c->key = v;
c->l = NIL;
c->r = NIL;
w... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *p;
struct node *r;
struct node *l;
int key;
};
typedef struct node *Node;
Node root;
void insert(int v) {
Node y = NIL;
Node x = root;
Node c;
c = malloc(sizeof(struct node));
c->key = v;
c->l = NIL;
c->r = NIL;
w... | [["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13]] | 0 | 480 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
struct node *root;
struct node *NIL;
struct node *find(struct node *, int);
void insert(int);
void inorder(struct node *);
void preorder(struct node *);
int main()... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *right;
struct node *left;
struct node *parent;
};
struct node *root;
struct node *NIL;
struct node *find(struct node *, int);
void insert(int);
void inorder(struct node *);
void preorder(struct node *);
int main()... | [["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 585 | 6 |
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct BST {
struct Node {
int data;
struct BST *left;
struct BST *right;
} * node;
} * BST;
typedef struct Node *Node;
BST BSTNewTree(void) {
BST empty = (BST)malloc(sizeof(struct BST));
empty->node = NULL;
... | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct BST {
struct Node {
int data;
struct BST *left;
struct BST *right;
} * node;
} * BST;
typedef struct Node *Node;
BST BSTNewTree(void) {
BST empty = (BST)malloc(sizeof(struct BST));
empty->node = NULL;
... | [["-", 0, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 16, 31, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 657 | 4 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *parent;
struct node *left;
struct node *right;
int key;
};
typedef struct node *Node;
void insert(Node, int);
void PrintInorder(Node);
void PrintPreorder(Node);
Node find(Node, int);
Node root, newnode;
main() {
int n, i, ... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *parent;
struct node *left;
struct node *right;
int key;
};
typedef struct node *Node;
void insert(Node, int);
void PrintInorder(Node);
void PrintPreorder(Node);
Node find(Node, int);
Node root, newnode;
main() {
int n, i, ... | [["-", 64, 37, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 64, 37, 0, 2, 3, 4, 0, 118, 119, 120]] | 0 | 535 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *parent; //親
struct Node *left; //左の子
struct Node *right; //右の子
};
typedef struct Node node;
node *insert(node *r, int k) {
node *x = r;
node *y = NULL;
node *z = (node *)malloc(sizeof(node));
z->key = k;... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
int key;
struct Node *parent; //親
struct Node *left; //左の子
struct Node *right; //右の子
};
typedef struct Node node;
node *insert(node *r, int k) {
node *x = r;
node *y = NULL;
node *z = (node *)malloc(sizeof(node));
z->key = k;... | [["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3,... | 0 | 589 | 10 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeSearch(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);
int main() {
int n, i, x;
char com[20]... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeSearch(Node, int);
void insert(int);
void inorder(Node);
void preorder(Node);
int main() {
int n, i, x;
char com[20]... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 538 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *p;
struct node *l;
struct node *r;
int key;
};
typedef struct node *Node;
Node Root = NULL;
void insert(int k) {
Node y = NULL;
Node x = Root;
Node new;
new = malloc(sizeof(struct node));
new->key = k;
new->l = NULL;
new->r = ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *p;
struct node *l;
struct node *r;
int key;
};
typedef struct node *Node;
Node Root = NULL;
void insert(int k) {
Node y = NULL;
Node x = Root;
Node new;
new = malloc(sizeof(struct node));
new->key = k;
new->l = NULL;
new->r = ... | [["+", 0, 57, 75, 76, 0, 57, 64, 37, 0, 38], ["+", 75, 76, 0, 57, 75, 76, 0, 37, 0, 38], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95]] | 0 | 503 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
int key;
struct node *parent;
struct node *right;
struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
int Find(int);
void Preorder(Node);
void Inorder(Node);
int main() {
int n, i, key;
char S[7];
scanf("%d", &n... | #include <stdio.h>
#include <stdlib.h>
struct node {
int key;
struct node *parent;
struct node *right;
struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
int Find(int);
void Preorder(Node);
void Inorder(Node);
int main() {
int n, i, key;
char S[7];
scanf("%d", &n... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 613 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node find(Node u, int k) {
if (u == NIL || ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node find(Node u, int k) {
if (u == NIL || ... | [["-", 64, 37, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 64, 37, 0, 2, 3, 4, 0, 118, 119, 120]] | 0 | 629 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | [["-", 0, 9, 0, 1, 0, 11, 12, 118, 119, 120], ["+", 0, 9, 0, 1, 0, 11, 12, 118, 119, 120]] | 0 | 486 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeSearch(Node u, int k) {
while (u !... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL)
x = x->left;
return x;
}
Node treeSearch(Node u, int k) {
while (u !... | [["-", 0, 52, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 52, 15, 23, 0, 16, 12, 16, 31, 22]] | 0 | 506 | 2 |
/**
* BInary Search tree (insert & search)
* output 1)node_number, 2)parent_number, 3)depth, 4)kind_of_node, 5)child_list
*/
/* inclution */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Definition */
#define MAX 500000
#define LEN 10
/* Global Variables */
struct Node {
int key;
struct Node *... | /**
* BInary Search tree (insert & search)
* output 1)node_number, 2)parent_number, 3)depth, 4)kind_of_node, 5)child_list
*/
/* inclution */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Definition */
#define MAX 500000
#define LEN 10
/* Global Variables */
struct Node {
int key;
struct Node *... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 573 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node find(Node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->right... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node find(Node u, int k) {
while (u != NIL && k != u->key) {
if (k < u->key)
u = u->left;
else
u = u->right... | [["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]] | 0 | 517 | 3 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int key;
struct node *p_left;
struct node *p_right;
struct node *p_parent;
} NODE;
void insert(int value); /* ?????\ */
void inorder(NODE *p_node); /* ??????????????? */
void preorder(NODE *p_node); /* ?????????... | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int key;
struct node *p_left;
struct node *p_right;
struct node *p_parent;
} NODE;
void insert(int value); /* ?????\ */
void inorder(NODE *p_node); /* ??????????????? */
void preorder(NODE *p_node); /* ?????????... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 584 | 4 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct TREE {
int id;
struct TREE *parent;
struct TREE *child[2];
int depth;
int height;
} Tree;
void insert(Tree *root, Tree *z) {
Tree *y = NULL;
Tree *x = root;
while (x != NULL) {
y = x;
if (z->id < x->id) {
x = x->ch... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct TREE {
int id;
struct TREE *parent;
struct TREE *child[2];
int depth;
int height;
} Tree;
void insert(Tree *root, Tree *z) {
Tree *y = NULL;
Tree *x = root;
while (x != NULL) {
y = x;
if (z->id < x->id) {
x = x->ch... | [["+", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 75, 76, 0, 57, 64, 9, 0, 37, 0, 38]] | 0 | 778 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *parent;
struct node *left;
struct node *right;
};
struct node *tree = NULL;
void insert(struct node **root, struct node *node) {
struct node *parent = NULL;
struct node *current = *root;
while (current != NU... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int key;
struct node *parent;
struct node *left;
struct node *right;
};
struct node *tree = NULL;
void insert(struct node **root, struct node *node) {
struct node *parent = NULL;
struct node *current = *root;
while (current != NU... | [["-", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["-", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6]] | 0 | 575 | 4 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeSearch(Node x, int k) {
while (x != NIL && k != x->key) {
if (k < x->key)
x = x->left;
else
x = x-... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeSearch(Node x, int k) {
while (x != NIL && k != x->key) {
if (k < x->key)
x = x->left;
else
x = x-... | [["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]] | 0 | 474 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root, NIL;
int maxh;
void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node, int);
int main() {
int n, i, x;
char com[2... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
Node root, NIL;
int maxh;
void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node, int);
int main() {
int n, i, x;
char com[2... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]] | 0 | 535 | 2 |
#include <stdio.h>
#include <stdlib.h>
struct Node {
int key;
struct Node *r, *l, *p;
};
struct Node *B, *NIL;
void insert(int k) {
struct Node *y = NIL;
struct Node *x = B;
struct Node *z;
z = (struct Node *)malloc(sizeof(struct Node));
z->key = k;
z->l = NIL;
z->r = NIL;
while (x != NIL) {
... | #include <stdio.h>
#include <stdlib.h>
struct Node {
int key;
struct Node *r, *l, *p;
};
struct Node *B, *NIL;
void insert(int k) {
struct Node *y = NIL;
struct Node *x = B;
struct Node *z;
z = (struct Node *)malloc(sizeof(struct Node));
z->key = k;
z->l = NIL;
z->r = NIL;
while (x != NIL) {
... | [["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 75, 76, 0, 57, 64, 9, 0, 1, 0, 35]] | 0 | 511 | 7 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL... | [["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60]] | 0 | 518 | 2 |
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));... | #include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
void insert(int k) {
Node y = NIL;
Node x = root;
Node z;
z = malloc(sizeof(struct node));... | [["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 511 | 6 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
return x;
}
}
Node treeMaximum(Node x) {
while ... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {
while (x->left != NIL) {
x = x->left;
return x;
}
}
Node treeMaximum(Node x) {
while ... | [["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]] | 0 | 668 | 2 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL -1
#define TRUE 1
#define FALSE 0
#define MAX 500000
typedef struct {
int parent;
int left;
int right;
int key;
} node;
void insert(int);
int find(int, int);
void inorder(int);
void preorder(int);
int root = -1;
node T[MAX];
int main() ... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NIL -1
#define TRUE 1
#define FALSE 0
#define MAX 500000
typedef struct {
int parent;
int left;
int right;
int key;
} node;
void insert(int);
int find(int, int);
void inorder(int);
void preorder(int);
int root = -1;
node T[MAX];
int main() ... | [["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["-", 15, 23, 0, 16, 31, 16, 12, 118, 119, 120], ["+", 15, 23, 0, 16, 31, 16, 12, 118, 119, 120]] | 0 | 629 | 4 |
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *l;
struct node *r;
struct node *p;
int key;
};
typedef struct node *Node;
Node root;
void Preorder(Node t) {
printf(" %d", t->key);
if (t != NIL) {
if (t->l != NIL)
Preorder(t->l);
if (t->r != NIL)
Pr... | #include <stdio.h>
#include <stdlib.h>
#define NIL NULL
struct node {
struct node *l;
struct node *r;
struct node *p;
int key;
};
typedef struct node *Node;
Node root;
void Preorder(Node t) {
printf(" %d", t->key);
if (t != NIL) {
if (t->l != NIL)
Preorder(t->l);
if (t->r != NIL)
Pr... | [["-", 0, 37, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 0, 37, 0, 2, 3, 4, 0, 118, 119, 120]] | 0 | 516 | 2 |
#include <iostream>
#include <stdio.h>
#include <string>
#define MAX 500000
struct node {
int key;
int parent, left, right;
} T[MAX];
int root;
void PrePrint(int t) {
if (t == -1)
return;
printf(" %d", T[t].key);
PrePrint(T[t].left);
PrePrint(T[t].right);
}
void InPrint(int t) {
if (t == -1)
r... | #include <iostream>
#include <stdio.h>
#include <string>
#define MAX 500000
struct node {
int key;
int parent, left, right;
} T[MAX];
int root;
void PrePrint(int t) {
if (t == -1)
return;
printf(" %d", T[t].key);
PrePrint(T[t].left);
PrePrint(T[t].right);
}
void InPrint(int t) {
if (t == -1)
r... | [["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]] | 1 | 574 | 2 |
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *p, *l, *r;
};
int n;
Node *NIL, *root;
void preorder(Node *u) {
if (u == NIL)
return;
cout << ' ' << u->key;
preorder(u->l);
preorder(u->r);
}
void inorder(Node *u) {
if (u == NIL)
return... | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *p, *l, *r;
};
int n;
Node *NIL, *root;
void preorder(Node *u) {
if (u == NIL)
return;
cout << ' ' << u->key;
preorder(u->l);
preorder(u->r);
}
void inorder(Node *u) {
if (u == NIL)
return... | [["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]] | 1 | 431 | 2 |
#include <iostream>
#define eol '\n';
using namespace std;
class Node {
public:
int k;
Node *p;
Node *l;
Node *r;
Node() : k(-1), p(nullptr), l(nullptr), r(nullptr){};
};
Node *root;
void insert(Node *z) {
Node *y = nullptr;
Node *x = root;
while (x != nullptr) {
y = x;
if (z->k < x->k) {
... | #include <iostream>
#define eol '\n';
using namespace std;
class Node {
public:
int k;
Node *p;
Node *l;
Node *r;
Node() : k(-1), p(nullptr), l(nullptr), r(nullptr){};
};
Node *root;
void insert(Node *z) {
Node *y = nullptr;
Node *x = root;
while (x != nullptr) {
y = x;
if (z->k < x->k) {
... | [["-", 0, 57, 15, 339, 51, 16, 12, 118, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 118, 28, 22]] | 1 | 498 | 2 |
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = new Node;
z->key = k;
z->left = NIL;
z->right = NIL;
while (x... | #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *y = NIL;
Node *x = root;
Node *z;
z = new Node;
z->key = k;
z->left = NIL;
z->right = NIL;
while (x... | [["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 79]] | 1 | 442 | 2 |
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
template <class T> struct Node {
T value;
size_t parent, left, right;
Node() : value(), parent(-1), left(-1), right(-1) {}
Node(T v) : value(v), parent(-1), left(-1), right(-1) {}
};
template <class T> struct Bina... | #include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
template <class T> struct Node {
T value;
size_t parent, left, right;
Node() : value(), parent(-1), left(-1), right(-1) {}
Node(T v) : value(v), parent(-1), left(-1), right(-1) {}
};
template <class T> struct Bina... | [["-", 12, 16, 31, 118, 28, 69, 341, 342, 0, 22], ["+", 12, 16, 31, 118, 28, 69, 341, 342, 0, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]] | 1 | 685 | 43 |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long ll;
int n;
struct node {
int l, r;
int key;
void init(int a) {
l = r = -1;
key = a;
}
};
struct bst {
int size;
node t[600001];
void init() { size = 0; }
void in... | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long ll;
int n;
struct node {
int l, r;
int key;
void init(int a) {
l = r = -1;
key = a;
}
};
struct bst {
int size;
node t[600001];
void init() { size = 0; }
void in... | [["-", 8, 9, 0, 43, 49, 50, 49, 352, 0, 67]] | 1 | 563 | 1 |
#include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {}
Node treeMaximum(Node x) {}
Node treeSearch(Node u, int k) {
Node x = u;
while (x != NIL) {
... | #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *right;
struct node *left;
struct node *parent;
int key;
};
typedef struct node *Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x) {}
Node treeMaximum(Node x) {}
Node treeSearch(Node u, int k) {
Node x = u;
while (x != NIL) {
... | [["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]] | 1 | 575 | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.