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.
Java Trees
Started by dazzyg, Aug 26 2009 02:17 PM
13 replies to this topic
#1
Posted 26 August 2009 - 02:17 PM
|
|
|
#2
Posted 26 August 2009 - 03:22 PM
#3
Posted 26 August 2009 - 03:29 PM
YouTube Classes !!!
YouTube - Broadcast Yourself.
YouTube - Broadcast Yourself.
Both are those are recorded playlists at universities, I watched the second one. I loved it.
YouTube - Broadcast Yourself.
YouTube - Broadcast Yourself.
Both are those are recorded playlists at universities, I watched the second one. I loved it.
#4
Posted 26 August 2009 - 04:30 PM
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.
Where as, the youtube classes will give you more details.
#5
Posted 26 August 2009 - 04:47 PM
Yea mine are def not brief haha
I got full semesters.. each are like an hour long.. and about 36~ videos....
I got full semesters.. each are like an hour long.. and about 36~ videos....
#6
Posted 27 August 2009 - 04:45 AM
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.
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.
#7
Posted 27 August 2009 - 06:58 AM
#8
Posted 27 August 2009 - 03:16 PM
OK, here is one of the apps Ive come up with.
I also have this node,
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?
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 :cursing:
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());
}
}
};
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 also have this node,
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 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?
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 :cursing:
#9
Posted 27 August 2009 - 04:03 PM
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.
#10
Posted 28 August 2009 - 01:12 PM
BlaineSch said:
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.
So can you not have 2 different types of nodes in the same tree structure?
#11
Posted 29 August 2009 - 12:56 AM
can u create an avl tree code for insertion and deletion?
kindly create one for me if you can.
kindly create one for me if you can.
#12
Posted 29 August 2009 - 03:30 AM
dazzyg said:
I tried this but its saying: incompatible types - its looking for a 'TreeNode' node and wont accept the 'SimpleNode' node as a child.
So can you not have 2 different types of nodes in the same tree structure?
So can you not have 2 different types of nodes in the same tree structure?
You probably can. If SimpleNode is an extension of TreeNode than you probably can.
glen19 said:
can u create an avl tree code for insertion and deletion?
kindly create one for me if you can.
kindly create one for me if you can.
No! We don't do homework for people. What do you have so far?


Sign In
Create Account

Back to top










