BST搜索完成失败 | AI生成和翻译

Home 2026.06

重要提示:在翻译Markdown内容时,请确保格式正确:

翻译规则:

以下是提示输入与模型输出的逐字对照:

=== 提示输入 (prompt_java.txt,第1-48行) ===

import java.util.*;

public class BinarySearchTree { private Node root;

  static class Node {
      int key;
      Node left, right;

      public Node(int item) {
          key = item;
          left = right = null;
      }
  }

  public BinarySearchTree() {
      root = null;
  }

  void insert(int key) {
      root = insertRec(root, key);
  }

  Node insertRec(Node root, int key) {
      if (root == null) {
          root = new Node(key);
          return root;
      }
      if (key < root.key)
          root.left = insertRec(root.left, key);
      else if (key > root.key)
          root.right = insertRec(root.right, key);
      return root;
  }

  void inorder() {
      inorderRec(root);
  }

  void inorderRec(Node root) {
      if (root != null) {
          inorderRec(root.left);
          System.out.println(root.key);
          inorderRec(root.right);
      }
  }

  boolean search(int key) {        <--- 提示在此结束

=== 模型续写 (300个新token,temp=0.8,top_k=200) ===

               return;              <--- 垃圾内容立即开始
       }
   }
   public String get(String source)
       { return text;
    }
     }
            return true  Property.TrveradataValue;   }
public Listi static
   {
        return new }  null;
       int() (int) {
             return new.Invalid(this.nameOf.Value);
    }
      this.value.n, this.v.S.S.S.S);
     }
         }
   return this.tree.GetAttribute(parent(this.name));

=== 结束 ===

提示(一个带有insert/inorder/search存根的完整BST)被原样重放。 随后在boolean search(int key) {之后,模型生成了:

模型显然从训练数据中记住了BST类,但无法连贯地完成search方法。


Back Donate