Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:58:31+00:00 2026-06-14T09:58:31+00:00

I’m trying to build an raw type BST , with Comparable<T> . The thing

  • 0

I’m trying to build an raw type BST, with Comparable<T>. The thing is somehow my declarations do something wrong, because I use in Node class type Comparable<type> and in BST class it errors with

The method setParent(Node<Comparable<Comparable<type>>>) in the type
Node<Comparable<type>> is not applicable for the arguments (Node<Comparable<type>>)
BinarySearchTree.java   /lab2/src   line 22 Java Problem

Node.java:

public class Node <type> {

    private Comparable<type> key;
    private Node <Comparable<type>> parent;
    private Node <Comparable<type>> leftChild;
    private Node <Comparable<type>> rightChild;

    public Node(Comparable<type> key, Node <Comparable<type>> leftChild, Node <Comparable<type>> rightChild) {
        this.setKey(key);
        this.setLeftChild(leftChild);
        this.setRightChild(rightChild);
    }

    public void setKey(Comparable<type> key) {
        this.key = key;
    }

    public Comparable<type> getKey() {
        return key;
    }

    public void setParent(Node<Comparable<type>> y) {
        this.parent =  y;
    }

    public Node <Comparable<type>> getParent() {
        return parent;
    }

    public void setLeftChild(Node <Comparable<type>> leftChild) {
        this.leftChild = leftChild;
    }

    public Node <Comparable<type>> getLeftChild() {
        return leftChild;
    }

    public void setRightChild(Node <Comparable<type>> rightChild) {
        this.rightChild =  rightChild;
    }

    public Node <Comparable<type>> getRightChild() {
        return rightChild;
    }
}

BinarySearchTree.java:

import java.util.Iterator;

public class BinarySearchTree<type> implements SortedSet<type> {

    private Node <Comparable<type>> root;

    public void insert(Node <Comparable<type>> z) {

        Node <Comparable<type>> y = null;
        Node <Comparable<type>> x = root;

        while (x != null) {
            y = x;

            if (z.getKey() < x.getKey()) { // ERROR '<' is undefined for type...
                x = x.getLeftChild();      // PARAM TYPE ERROR
            } else {
                x = x.getRightChild();     // PARAM TYPE ERROR
            }
        }

        z.setParent(y);

        if (y == null) {
            root = z;
        } else if (z.getKey() < y.getKey()) {
            y.setLeftChild(z);
        } else {
            y.setRightChild(z);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:58:32+00:00Added an answer on June 14, 2026 at 9:58 am

    Consider to refactoring to the following code

    import java.util.SortedSet;
    
    public abstract class BinarySearchTree<T extends Comparable<T>> implements SortedSet<T> {
      private Node<T> root;
    
      class Node<T extends Comparable<T>> {
    
        private T key;
        private Node<T> parent;
        private Node<T> leftChild;
        private Node<T> rightChild;
    
        public Node(T key, Node<T> leftChild, Node<T> rightChild) {
          this.setKey(key);
          this.setLeftChild(leftChild);
          this.setRightChild(rightChild);
        }
    
        public void setKey(T key) {
          this.key = key;
        }
    
        public T getKey() {
          return key;
        }
    
        public void setParent(Node<T> y) {
          this.parent =  y;
        }
    
        public Node <T> getParent() {
          return parent;
        }
    
        public void setLeftChild(Node <T> leftChild) {
          this.leftChild = leftChild;
        }
    
        public Node <T> getLeftChild() {
          return leftChild;
        }
    
        public void setRightChild(Node <T> rightChild) {
          this.rightChild =  rightChild;
        }
    
        public Node <T> getRightChild() {
          return rightChild;
        }
      }
    
      public void insert(Node<T> z) {
    
        Node<T> y = null;
        Node<T> x = root;
    
        while (x != null) {
          y = x;
    
          if (z.getKey().compareTo(x.getKey()) < 0) {
            x = x.getLeftChild();
          } else {
            x = x.getRightChild();
          }
        }
    
        z.setParent(y);
    
        if (y == null) {
          root = z;
        } else if (z.getKey().compareTo((T) y.getKey()) <0) {
          y.setLeftChild(z);
        } else {
          y.setRightChild(z);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.