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

  • Home
  • SEARCH
  • 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 5985037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:28:11+00:00 2026-05-22T22:28:11+00:00

For homework I was assigned to make an AVL Tree data structure. I am

  • 0

For homework I was assigned to make an AVL Tree data structure.
I am trying to make my “add” method to add a piece of generic data to the tree.
My problem is that in the assignment we must extend a class that was given to us called “BinaryTree”.
Within my add method I need to use the compareTo method, which I believe means that I also have to Extend Comparable.
I have looked online and apparently you cannot extend two classes so this becomes a problem. I decided to try to write my own compareTo method in my AVL tree class but it says the < and > cannot be applied to my generic type.
Any hints or quick workarounds? or am I just being dumb?

Thanks
– Steve

  • 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-05-22T22:28:11+00:00Added an answer on May 22, 2026 at 10:28 pm

    You can use Generics to specify the type and require that it implements Comparable. That way you have access to both the type and compareTo() within the AVL Tree.

    public class AVL<T extends Comparable<T>> extends BinaryTree {
    
        public void add(T object) {
                ...
            object.compareTo(some other object)
                ...
        }
    }
    

    Then you would create it as AVL<MyObject> avl = new AVL<MyObject>()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a homework assignment I was given a Card class that has enumerated types
I'm a cis221 student, and I've been assigned a piece of homework I simply
A homework assignment asks me to implement a program that counts the words in
I'm doing a basic homework assignment which looks like this: While input <> -1
Disclaimer: This is for a homework assignment, but the question is not regarding the
This IS NOT homework, but it is a practice that the teacher gave us
This is not a homework problem, though it is a work problem. Where months
I just finished a homework problem for Computer Science 1 (yes, it's homework, but
I have a homework that I just can't figure out how to do. I'm
I am attempting to create a simple language interpreter for a homework assignment in

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.