Results 1 to 1 of 1
Thread: Main Method Help
- 03-12-2010, 01:20 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Main Method Help
Hi there. Relatively new to Java. I have an assignment which is split into parts, based on a username/password idea. First part was to create a data structure appropriate for my project and I could add items to it. Done this using a Binary Search Tree. There appears to be no error in the code, but I can't figure out how to create a main method to make sure it works properly.
Any help with a main method would be greatly appreciated, grateful for any other suggestions or improvements. ThanksJava Code:public class BTree { String username; String password; BTree left; BTree right; public BTree (String u, String p, BTree l, BTree r) { username = u; password = p; left = l; right = r; } public BTree (String u, String p) { username = u; password = p; left = null; right = null; } } public BTree addToBTree(String u, String p, BTree t) { if (t == null) return (new BTree(u, p)); if (before (u, t.username)) return (new BTree(t.username, t.password, addToBTree(u, p, t.left), t.right)); else return (new BTree(t.username, t.password, t.left, addToBTree(u, p, t.right))); } public static boolean before (String s1, String s2){ if (s1.length() == 0) return true; if (s2.length() == 0) return false; if (s1.charAt(0) < s2.charAt(0)) return true; if (s1.charAt(0) == s2.charAt(0)) return (before(s1.substring(1),s2.substring(1))); return false; } public static void printBST(BTree t){ if (t == null) return; else {printBST(t.left); System.out.println(t.username); System.out.println(t.password); printBST(t.right); } } }
Similar Threads
-
Help with main method
By eliCanzee in forum JDBCReplies: 4Last Post: 01-06-2010, 09:12 AM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
Main method here to :S:S hlp pls
By eliCanzee in forum AWT / SwingReplies: 6Last Post: 05-27-2009, 04:45 AM -
Help me for main method
By eliCanzee in forum AWT / SwingReplies: 1Last Post: 05-26-2009, 12:43 PM -
main method
By eva in forum New To JavaReplies: 5Last Post: 12-19-2007, 09:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks