3 Replies Latest reply: May 18, 2010 2:33 AM by 843853

# need ideas to solve my priority algorithm

|---0
|---A
|---B
|---C
|---D
|---E
|---F
|---G
|---1
|---H

i converted this to
0 mapped to list of
1 A
1 B
2 C
3 D
3 E
1 F
2 G
1 mapped to list of
1 H

here i have mapped the nos to respective spaces that explain their order or hierarchy
i need to put them is a data structure where i can process them based on their hierarchy.
any ideas about the implementation ?
its really an interesting issue !!

thanks
Jay

Edited by: jadurairaj on Mar 25, 2010 3:21 PM
• ###### 1. Re: need ideas to solve my priority algorithm
its really an interesting issue !!
If I understood what it was about I might be able to judge how interesting it is.
• ###### 2. Re: need ideas to solve my priority algorithm
``````|---0
|---A
|---B
|---C
|---D
|---E
|---F
|---G
|---1
|---H``````
...

here i have mapped the nos to respective spaces that explain their order or hierarchy
i need to put them is a data structure where i can process them based on their hierarchy.
any ideas about the implementation ?
> ...

Here's an idea:
``````class Tree {

private Node root;

// ...

private static class Node {
String value;
List<Node> children;
// ...
}
}``````
• ###### 3. Re: need ideas to solve my priority algorithm
You can use a node structure of this kind also:
``````class Node{
Node child;
Node rightSibling; //right sibling
/* Add more members if you want some information present in the node */
}``````
- Add a child when ever priority increases. So the height/level indicates the priority
- Add a right sibling if element of same priority occurs

With the current node structure you can move from left to right (or top to bottom). If you wan to navigate from right to left, add another member to node class called "leftSubling". So by using this node you can construct the tree using three references to other objects without using arrays/vectors.