Hi,
I am doing a project using a java tree structure. Is there any good websites or tutorials that could help me out to get me going? I tried google but couldnt find what Im looking for.
Or could someone give me a few pointers to get going?
Basically, I need to create a class for representing artists and their tracks, but I have to address artist nodes inside the tree structure using an array of ints referring to the subnodes by their index?
Im familiar with the different lists like linked lists, queues and stacks but not too up on trees.
Have a look here: Java Data Structures (2nd edition) - End of the World Production, LLC..
YouTube Classes !!!
YouTube - Broadcast Yourself.
YouTube - Broadcast Yourself.
Both are those are recorded playlists at universities, I watched the second one. I loved it.
Those videos will help you A LOT!!! If you just want a brief introduction my web site above is rather decent. It gives a brief introduction to the different structures to get you up and going.
Where as, the youtube classes will give you more details.
Yea mine are def not brief haha
I got full semesters.. each are like an hour long.. and about 36~ videos....
thanks guys. I looked at the youtube vids but I kinda already have a grasp of the architecture and how it works, I was looking for some code to see how its implemented. there is nothing really in the youtube videos about the actual implementation but they were a helpful mind refresh and a great lecture too.
Chilli's link is something like what im after. But i would like to get a vey basic, simple working app to tinker with the code and see how I could implement my own version.
OK, here is one of the apps Ive come up with.
Code:public class TreeNode<Bookmark> { private Bookmark bookmark; private TreeNode<Bookmark> next; private TreeNode<Bookmark> subnodes; public TreeNode(Bookmark bookmark, TreeNode<Bookmark> subnodes, TreeNode<Bookmark> next) { this.bookmark = bookmark; this.subnodes = subnodes; this.next = next; } public TreeNode findSubNode(Bookmark itemToMatch) { for (TreeNode sub = subnodes; sub != null; sub = sub.next) { if (sub.bookmark.equals(itemToMatch)) { return sub; } } return null; } public void addSubNode(TreeNode<Bookmark> child) { child.next = subnodes; subnodes = child; } public void setSubnodes(TreeNode<Bookmark> subnodes) { this.subnodes = subnodes; } public TreeNode<Bookmark> getSubNodes() { return this.subnodes; } public Bookmark getBookmark() { return this.bookmark; } public String toString() { String str = recursiveToString("", 0); return str; } public TreeNode<Bookmark> getNext() { return this.next; } private String recursiveToString(String str, int indent) { for (int i = 0; i < indent; i++) { str += " "; } str += bookmark.toString(); str += "\n"; indent += 3; TreeNode<Bookmark> sub = subnodes; while (sub != null) { str = sub.recursiveToString(str, indent); sub = sub.getNext(); } return str; } public void displaySubNodes() { System.out.println("Contents of " + bookmark); for (TreeNode<Bookmark> sub = subnodes; sub != null; sub = sub.next) { System.out.println(sub.getBookmark()); } } };I also have this node,Code:public class Main { public static void main(String[] args) { //Initial Root Node TreeNode<String> root = new TreeNode("Firefox Bookmarks", null, null); //Initial Sub Nodes root.addSubNode(new TreeNode<String>("Favourite Bookmarks", null, null)); TreeNode<String> tnode = new TreeNode<String>("College Bookmarks", null, null); root.addSubNode(tnode); tnode.addSubNode(new TreeNode<String>("Java", null, null)); //Initial Bookmark //SimpleNode<String> snode = new SimpleNode<String>("Google", "googlecom"); //root.addSimpleNode(snode); System.out.println(root); InputStreamReader input = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(input); System.out.println("Add Bookmarks..."); System.out.print("Enter Bookmark: "); String bookmark; try { bookmark = reader.readLine(); System.out.println("Searching... " + bookmark); TreeNode treenode = root.findSubNode(bookmark); if (treenode == null) System.out.println("No Such Bookmark"); else { System.out.println(treenode); } /*System.out.println("Add a Bookmark Folder..."); System.out.print("Enter Name: "); String bookmarkFolder = reader.readLine(); treenode.addSubNode(new TreeNode(bookmarkFolder, null, null)); System.out.println(treenode);*/ } catch (Exception e) { e.printStackTrace(); } } }
I basically want to have a root node, then the treenode to hold bookmark folders(which can have subfolders) with simplenodes attached to them to hold the url name and address. But I cant figure out how to add the simplenode as a subnode of the root?Code:public final class SimpleNode<Bookmark> { private String name; private String url; public SimpleNode(String name, String url) { this.name = name; this.url = url; } public void addSimpleNode(SimpleNode<Bookmark> child) { //insert code } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }
I want to be able to have a list of bookmarks and a list of bookmarks in folders(which in turn can have subfolders)
I dont know how clear I am being - i cannot post a picture to explain it a bit better
Anyone got an answer?
thanks![]()
To add a "next" you create a new node, then link "root.next = new" or something. All objects are pointers so do not worry about using space when copying them.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks