Question:
How to program a binary search tree in Java?
GreenFairy
2013-04-01 11:27:04 UTC
Hello,
Does anyone know how to go about writing a program in Java which sorts a list of integers using a binary search tree?

Thankyou
Three answers:
Kaydell
2013-04-02 00:05:21 UTC
You'll need two classes:



1. Tree



and



2. Node



The Tree class will just need one instance variable



private Node root = null;



In the Tree class, everything can be pretty simple for each different kind of operation whether it be insert(), delete(), or find().



First check if root is null, if so immediately return the appropriate result. For example, for a find() if the root is null, return a null Integer. (declare all of your integers using the object type Integer so that you can return null in cases like this.)



Next, root isn't null, so you can make calls like:



return root.find();

return root.insert();



etc.



Then for Node, you would also declare find() insert() etc.



I may be loosing you. If you want to chat me up on Yahoo! Messenger, I can walk you through it. My Yahoo! Messenger ID is: "kaydell" and my email address is: "kaydell@yahoo.com"
2014-10-23 16:02:30 UTC
I'm making good profit with penny stock

Check here http://trade-pennystock.checkhere.info



Many new investors are lured to the appeal of a penny stock due to the low price and potential for rapid growth which may be as high as several hundred percent in a few days. Similarly, severe loss can occur and many penny stocks lose all of their value in the long term. Accordingly, the SEC warns that penny stocks are high risk investments and new investors should be aware of the risks involved but you can even make very big money. These risks include limited liquidity, lack of financial reporting, and fraud. A penny stock is a common stock that trades for less than $5 a share. While penny stocks generally are quoted over-the-counter, such as on the OTC Bulletin Board or in the Pink Sheets, they may also trade on securities exchanges, including foreign securities exchanges. In addition, penny stocks include the securities of certain private companies with no active trading market. Although a penny stock is said to be "thinly traded," share volumes traded daily can be in the hundreds of millions for a sub-penny stock. Legitimate information on penny stock companies can be difficult to find and a stock can be easily manipulated.
deonejuan
2013-04-01 11:48:13 UTC
See if this college book example explains it enough. I assume you are writing your own Tree and not using the Java API TreeSet.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...