The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Java


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: , , , ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #11 (permalink)  
Old 08-05-2007, 04:10 PM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
I take it to mean that you're confident with your insert now? (Your inorder function looked fine). Obviously, if the insert has any problems, the likelyhood is that the rest will fall apart too.

The delete algorithm is a bit more complicated, since the method of removing a node depends on the number of 'children' that node has (one, two, or none).

If you're still wrapping your head around recursion, try making a 'find' method, or, maybe something unrelated to the BST (in general, any 'while' loop can be rearranged as a recursive loop some way or another)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #12 (permalink)  
Old 08-05-2007, 04:51 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Next, inorder(NULL) returns. This removes it from the stack frame, leaving inorder("1") back at the top. Inorder("1") must take up from where it left off, so the next statement is
That part is the most confusing to me, since it returns, doesn't that meant hat it should be getting out from the method itself? How can it pick up from where it left off?

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #13 (permalink)  
Old 08-05-2007, 05:01 PM
Leech
Posts: n/a
Don't know if this will help but wikipedia has some C++ code for deletion.

Binary search tree - Wikipedia, the free encyclopedia

Best of luck on your coding.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #14 (permalink)  
Old 08-05-2007, 05:20 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Quote:
Originally Posted by Leech View Post
Don't know if this will help but wikipedia has some C++ code for deletion.

Binary search tree - Wikipedia, the free encyclopedia

Best of luck on your coding.
LOL Leech,
I appreciate that. Unfortunately,
1. I've been there
2. I've been to many places that gives example, but most of them uses Comparable, which something that I don't want to use for now to keep it simpler. (if this is even possible)
3. I've been Googling

Quote:
I take it to mean that you're confident with your insert now? (Your inorder function looked fine). Obviously, if the insert has any problems, the likelyhood is that the rest will fall apart too.

The delete algorithm is a bit more complicated, since the method of removing a node depends on the number of 'children' that node has (one, two, or none).

If you're still wrapping your head around recursion, try making a 'find' method, or, maybe something unrelated to the BST (in general, any 'while' loop can be rearranged as a recursive loop some way or another)
Yes, I finished implementing the new one, I forgot return;

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by HelloWorld : 08-05-2007 at 05:37 PM.
Reply With Quote
  #15 (permalink)  
Old 08-05-2007, 06:02 PM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
Quote:
Originally Posted by HelloWorld View Post
That part is the most confusing to me, since it returns, doesn't that meant hat it should be getting out from the method itself? How can it pick up from where it left off?
I'd like to elaborate on something I mentioned in my previous post
Quote:
Originally Posted by Bench
Recursion causes multiple different calls of the same function to be placed on a stack frame.
In other words, recursion causes multiple instances of a method-call to be created. In this context, it would be sensible to think of a method-call as an object with a presence in memory.. or at least, on the stack frame, which will be active in memory somewhere, recording the state of individual method-calls.

You can think of a Method/function as a Named block of code. Its almost like meta-programming, where a single-line method-call is replaced by the contents of that entire method.

for example, here's a program with some nested method calls. Exactly the same thing happens with the stack frame as the recursive calls before, just with different methods.
PHP Code:
public static void DoSomething()
{
    
System.out.println("DoSomething is added on-top of the stack frame");
}

public static void SomeMethod()
{
    
System.out.println("SomeMethod is added on-top of the stack frame");
    
DoSomething();
    
System.out.println("SomeMethod at the top again");
}

public static void main(String args[])
{
    
System.out.println("main is at the top of the stack frame");
    
SomeMethod();
    
System.out.println("main is at the top of the stack frame again");

If you un-rolled the stack frame in-to main, the program would look like this
PHP Code:
public static void main(String args[])
{
   
System.out.println("main is at the top of the stack frame");

      
//Begin SomeMethod()
      
System.out.println("SomeMethod is added on-top of the stack frame");
         
//Begin DoSomething()
         
System.out.println("DoSomething is added on-top of the stack frame");
         
//End DoSomething()
      
System.out.println("SomeMethod at the top again");
      
//End SomeMethod()

   
System.out.println("main is at the top of the stack frame again"); 
at the point when DoSomething() is called, the stack frame looks like this
Code:
-top-
  DoSomething()
  SomeMethod()
  main()
-bottom-
If you run the program, you should be able to see that when DoSomething() ends, the function returns to the point in SomeMethod() where DoSomething() was called from. Because SomeMethod is temporarily 'frozen', with its state recorded on the stack frame - therefore, it picks up where it left off when it becomes active again

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Bench : 08-05-2007 at 06:26 PM.
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (08-06-2007)
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:15 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50