Tree interface for ArrayList

Reply

Join Date: Nov 2008
Posts: 2
Reputation: dixi is an unknown quantity at this point 
Solved Threads: 0
dixi dixi is offline Offline
Newbie Poster

Tree interface for ArrayList

 
0
  #1
Nov 24th, 2008
Hi! I'm trying to define a list of objects that could be a binary tree or a Processtrees.
The binary tree is already defined and works fine, don't worry about it.

A Processtree is a binary tree generated by a Process, a Process is defined by a Name and a State

Processtree looks like this:

Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree, but I need to define a list of objects that could be a Binary tree or a Processtree.
The Processtree implementation may change, so I think I should define a common Tree interface and make Processtree and Binary tree implement it, but I don't know if I could define an ArrayList of this Tree..
I'm new to java, thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: Tree interface for ArrayList

 
0
  #2
Nov 24th, 2008
Originally Posted by dixi View Post

Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree
if this is all the code you have in Processtree, you might want to worry though.
a better approach is to declare all your variables there private and to use getters and setters to get or manipulate their values
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: Tree interface for ArrayList

 
0
  #3
Nov 25th, 2008
You can implement a common tree interface based on your current BTree class then you can have two options, First, you code PTree from common tree or Second you can inherit BTree to code your PTree if PTree is a kind of "Binary" tree.

The following is a tree interface:

interface CommonTree <T> {
public T getData();
public int getNodes();
public boolean IsEmpty();
public void Clear();

}
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: dixi is an unknown quantity at this point 
Solved Threads: 0
dixi dixi is offline Offline
Newbie Poster

Re: Tree interface for ArrayList

 
0
  #4
Dec 1st, 2008
PTree is a kind of Binary tree so your Second solution works fine, but now my boss wants me to create a List of objects that can be a Binary tree or what he calls a Forest:
Forest{
NameProc
Array[s1,s2,...sn] of Binary tree
}

So I need to create a list that looks like this: BT-F-F-BT-F...
where BT is the Binary tree and F is a Forest.
Each forest is defined by the process name and an array of binary trees, the array is indexed by the states s1,..sn that are the states of the process, each state generates a different Binary tree..
This array is not the problem because I think I can use a map, but I don't know how to create a list of objects that are so different, could that be possible to create a list of binary trees and Forests using an interface?
Any help please
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC