Search Results

Search found 4391 results on 176 pages for 'tree hacker'.

Page 9/176 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Binary Search Tree Implementation

    - by Gabe
    I've searched the forum, and tried to implement the code in the threads I found. But I've been working on this real simple program since about 10am, and can't solve the seg. faults for the life of me. Any ideas on what I'm doing wrong would be greatly appreciated. BST.h (All the implementation problems should be in here.) #ifndef BST_H_ #define BST_H_ #include <stdexcept> #include <iostream> #include "btnode.h" using namespace std; /* A class to represent a templated binary search tree. */ template <typename T> class BST { private: //pointer to the root node in the tree BTNode<T>* root; public: //default constructor to make an empty tree BST(); /* You have to document these 4 functions */ void insert(T value); bool search(const T& value) const; bool search(BTNode<T>* node, const T& value) const; void printInOrder() const; void remove(const T& value); //function to print out a visual representation //of the tree (not just print the tree's values //on a single line) void print() const; private: //recursive helper function for "print()" void print(BTNode<T>* node,int depth) const; }; /* Default constructor to make an empty tree */ template <typename T> BST<T>::BST() { root = NULL; } template <typename T> void BST<T>::insert(T value) { BTNode<T>* newNode = new BTNode<T>(value); cout << newNode->data; if(root == NULL) { root = newNode; return; } BTNode<T>* current = new BTNode<T>(NULL); current = root; current->data = root->data; while(true) { if(current->left == NULL && current->right == NULL) break; if(current->right != NULL && current->left != NULL) { if(newNode->data > current->data) current = current->right; else if(newNode->data < current->data) current = current->left; } else if(current->right != NULL && current->left == NULL) { if(newNode->data < current->data) break; else if(newNode->data > current->data) current = current->right; } else if(current->right == NULL && current->left != NULL) { if(newNode->data > current->data) break; else if(newNode->data < current->data) current = current->left; } } if(current->data > newNode->data) current->left = newNode; else current->right = newNode; return; } //public helper function template <typename T> bool BST<T>::search(const T& value) const { return(search(root,value)); //start at the root } //recursive function template <typename T> bool BST<T>::search(BTNode<T>* node, const T& value) const { if(node == NULL || node->data == value) return(node != NULL); //found or couldn't find value else if(value < node->data) return search(node->left,value); //search left subtree else return search(node->right,value); //search right subtree } template <typename T> void BST<T>::printInOrder() const { //print out the value's in the tree in order // //You may need to use this function as a helper //and create a second recursive function //(see "print()" for an example) } template <typename T> void BST<T>::remove(const T& value) { if(root == NULL) { cout << "Tree is empty. No removal. "<<endl; return; } if(!search(value)) { cout << "Value is not in the tree. No removal." << endl; return; } BTNode<T>* current; BTNode<T>* parent; current = root; parent->left = NULL; parent->right = NULL; cout << root->left << "LEFT " << root->right << "RIGHT " << endl; cout << root->data << " ROOT" << endl; cout << current->data << "CURRENT BEFORE" << endl; while(current != NULL) { cout << "INTkhkjhbljkhblkjhlk " << endl; if(current->data == value) break; else if(value > current->data) { parent = current; current = current->right; } else { parent = current; current = current->left; } } cout << current->data << "CURRENT AFTER" << endl; // 3 cases : //We're looking at a leaf node if(current->left == NULL && current->right == NULL) // It's a leaf { if(parent->left == current) parent->left = NULL; else parent->right = NULL; delete current; cout << "The value " << value << " was removed." << endl; return; } // Node with single child if((current->left == NULL && current->right != NULL) || (current->left != NULL && current->right == NULL)) { if(current->left == NULL && current->right != NULL) { if(parent->left == current) { parent->left = current->right; cout << "The value " << value << " was removed." << endl; delete current; } else { parent->right = current->right; cout << "The value " << value << " was removed." << endl; delete current; } } else // left child present, no right child { if(parent->left == current) { parent->left = current->left; cout << "The value " << value << " was removed." << endl; delete current; } else { parent->right = current->left; cout << "The value " << value << " was removed." << endl; delete current; } } return; } //Node with 2 children - Replace node with smallest value in right subtree. if (current->left != NULL && current->right != NULL) { BTNode<T>* check; check = current->right; if((check->left == NULL) && (check->right == NULL)) { current = check; delete check; current->right = NULL; cout << "The value " << value << " was removed." << endl; } else // right child has children { //if the node's right child has a left child; Move all the way down left to locate smallest element if((current->right)->left != NULL) { BTNode<T>* leftCurrent; BTNode<T>* leftParent; leftParent = current->right; leftCurrent = (current->right)->left; while(leftCurrent->left != NULL) { leftParent = leftCurrent; leftCurrent = leftCurrent->left; } current->data = leftCurrent->data; delete leftCurrent; leftParent->left = NULL; cout << "The value " << value << " was removed." << endl; } else { BTNode<T>* temp; temp = current->right; current->data = temp->data; current->right = temp->right; delete temp; cout << "The value " << value << " was removed." << endl; } } return; } } /* Print out the values in the tree and their relationships visually. Sample output: 22 18 15 10 9 5 3 1 */ template <typename T> void BST<T>::print() const { print(root,0); } template <typename T> void BST<T>::print(BTNode<T>* node,int depth) const { if(node == NULL) { std::cout << std::endl; return; } print(node->right,depth+1); for(int i=0; i < depth; i++) { std::cout << "\t"; } std::cout << node->data << std::endl; print(node->left,depth+1); } #endif main.cpp #include "bst.h" #include <iostream> using namespace std; int main() { BST<int> tree; cout << endl << "LAB #13 - BINARY SEARCH TREE PROGRAM" << endl; cout << "----------------------------------------------------------" << endl; // Insert. cout << endl << "INSERT TESTS" << endl; // No duplicates allowed. tree.insert(0); tree.insert(5); tree.insert(15); tree.insert(25); tree.insert(20); // Search. cout << endl << "SEARCH TESTS" << endl; int x = 0; int y = 1; if(tree.search(x)) cout << "The value " << x << " is on the tree." << endl; else cout << "The value " << x << " is NOT on the tree." << endl; if(tree.search(y)) cout << "The value " << y << " is on the tree." << endl; else cout << "The value " << y << " is NOT on the tree." << endl; // Removal. cout << endl << "REMOVAL TESTS" << endl; tree.remove(0); tree.remove(1); tree.remove(20); // Print. cout << endl << "PRINTED DIAGRAM OF BINARY SEARCH TREE" << endl; cout << "----------------------------------------------------------" << endl; tree.print(); cout << endl << "Program terminated. Goodbye." << endl << endl; } BTNode.h #ifndef BTNODE_H_ #define BTNODE_H_ #include <iostream> /* A class to represent a node in a binary search tree. */ template <typename T> class BTNode { public: //constructor BTNode(T d); //the node's data value T data; //pointer to the node's left child BTNode<T>* left; //pointer to the node's right child BTNode<T>* right; }; /* Simple constructor. Sets the data value of the BTNode to "d" and defaults its left and right child pointers to NULL. */ template <typename T> BTNode<T>::BTNode(T d) : left(NULL), right(NULL) { data = d; } #endif Thanks.

    Read the article

  • Tortoise SVN tree conflict with myself

    - by Jesse Pepper
    Has anyone had the experience of moving a file in tortoise and committing successfully, only to later commit a different change and be told of a tree conflict where: the file in its original location has been deleted, but in tortoise is marked as missing the file in its new location is there, but marked as already added. (I use tortoise SVN, and we have client and server 1.60) Nobody else changed either the directory or the file (according to svn log). Why is this happening? Is there a way to avoid it happening? If it does happen, is there a more elegant way of fixing the problem than by deleting the whole folder and updating again?

    Read the article

  • B-Tree Revision

    - by stan
    Hi, If we are looking for line intersections (horizontal and vertical lines only) and we have n lines with half of them vertical and no intersections then Sorting the list of line end points on y value will take N log N using mergesort Each insert delete and search of our data structue (assuming its a b-tree) will be < log n so the total search time will be N log N What am i missing here, if the time to sort using mergesort takes a time of N log N and insert and delete takes a time of < log n are we dropping the constant factor to give an overal time of N log N. If not then how comes < log n goes missing in total ONotation run time? Thanks

    Read the article

  • (External) Java library for creating Tree structure ?

    - by suVasH.....
    I am planning to implement a tree structure where every node has two children and a parent along with various other node properties (and I'd want to do this in Java ) Now, the way to it probably is to create the node such that it links to other nodes ( linked list trick ), but I was wondering if there is any good external library to handle all this low level stuff. ( for eg. the ease of stl::vector vs array in C++ ). I've heard of JDots, but still since i haven't started (and haven't programmed a lot in Java), I'd rather hear out before I begin.

    Read the article

  • Speech.Recognition GrammarBuilder/Choices Tree Structure

    - by user2210179
    In playing around with C#'s Speech Recognition, I've stumbled across a road block in the creation of an effective GrammerBuilder with Choices (more specifically, Choices of Choices). IE considering the following logical commands. One solution would to "hard code" every combination of Speech lines and add them to a GrammarBuilder (ie "SET LEFT COLOR RED" and "SET RIGHT CLEAR", however, this would quickly max out the limit of 1024, especially when dealing with number combinations. Another solution would to Append all 'columns' as "Choices" (and filter out incorrect paths upon 'recognition', however this seems like it's processor heavy and unnecessary. The middle ground, seems like the best path - with Choices of Choices - like a tree structure on a GrammarBuilder - however I'm not sure how to proceed. Any suggestions?

    Read the article

  • Unix tree convert to recursive php array

    - by Fordnox
    I have a response from remote server like this: /home/computer/Downloads |-- /home/computer/Downloads/Apple | `-- /home/computer/Downloads/Apple/Pad |-- /home/computer/Downloads/Empty_Folder `-- /home/computer/Downloads/Subfolder |-- /home/computer/Downloads/Subfolder/Empty `-- /home/computer/Downloads/Subfolder/SubSubFolder `-- /home/computer/Downloads/Subfolder/SubSubFolder/Test this is the output for command computer@athome:$ tree -df --noreport -L 5 /home/computer/Downloads/ I would like to parse this string to recursive php array or object, something like this. I would show only part of result to get the idea. array( 'title' => '/home/computer/Downloads', 'children' => array( 0 => array( 'title' => '/home/computer/Downloads/Apple', 'children' => array( ... ) ) ); Response from server can change according to scanned directory. Can someone help me write this function. Please note that this is response from remote server and php functions can not scan any remote dir.

    Read the article

  • Recursive Binary Search Tree Insert

    - by Nick Sinklier
    So this is my first java program, but I've done c++ for a few years. I wrote what I think should work, but in fact it does not. So I had a stipulation of having to write a method for this call: tree.insertNode(value); where value is an int. I wanted to write it recursively, for obvious reasons, so I had to do a work around: public void insertNode(int key) { Node temp = new Node(key); if(root == null) root = temp; else insertNode(temp); } public void insertNode(Node temp) { if(root == null) root = temp; else if(temp.getKey() <= root.getKey()) insertNode(root.getLeft()); else insertNode(root.getRight()); } Thanks for any advice.

    Read the article

  • WPF component for 2D tree diagram

    - by pdm2011
    I'm looking for a well-documented, supported WPF component that provides an API for visualisation of 2D tree diagrams. Ideally something easy to use, customisable (i.e. supports various flavours of nodes and splines) and preferably with automated layout control. Tools that look good so far are GoXam (http://www.nwoods.com/components/silverlight-wpf/goxam-overview.htm) and yFiles WPF (http://www.yworks.com/en/products_yfileswpf_about.html). Just wondering if anyone has experience with either of these, or can recommend an alternative? Thanks!

    Read the article

  • A B+tree simple implementation in C

    - by initpy
    Hi guys, I'm working on a fun project where I need a simple key/value store that uses B+Trees. I studied them some years ago, and to be honest, I don't want to reinvent the wheel, so I'm looking for a simple implementation in C of b+tree that I can just include in my project. I know of sqlite's, dbm's and tokyocabinet's ones but they're a little too "complicated" for my needs. Is there any (even pedagogical) work on this you can refer me to? Do you have some code to share? Thanks a lot!

    Read the article

  • Flex: change item Style on certain Tree based ItemRenderers

    - by Markus
    Hi Everybody, I have a question concerning Tree items. I want to show where a drop action would be placed... The item will be placed in between two existing elements. So what I want to do is, to take the upper item and draw a line underneath it. But I struggling to address the itemRenderer... I have the index for the itemrenderer, but I dont get a instance of that object. Any help is appreciated! Markus

    Read the article

  • In a binary search Tree

    - by user1044800
    In a binary search tree that takes a simple object.....when creating the getter and setter methods for the left, right, and parent. do I a do a null pointer? as in this=this or do I create the object in each method? Code bellow... This is my code: public void setParent(Person parent) { parent = new Person( parent.getName(), parent.getWeight()); //or is the parent supposed to be a null pointer ???? This is the code it came from: public void setParent(Node parent) { this.parent = parent; } Their code takes a node from the node class...my set parent is taking a person object from my person class.....

    Read the article

  • Stuck on solving the Minimal Spanning Tree problem.

    - by kunjaan
    I have reduced my problem to finding the minimal spanning tree in the graph. But I want to have one more constraint which is that the total degree for each vertex shouldnt exceed a certain constant factor. How do I model my problem? Is MST the wrong path? Do you know any algorithms that will help me? One more problem: My graph has duplicate edge weights so is there a way to count the number of unique MSTs? Are there algorithms that do this? Thank You. Edit: By degree, I mean the total number of edges connecting the vertex. By duplicate edge weight I mean that two edges have the same weight.

    Read the article

  • movedown method not saving new position - cakephp tree

    - by Ryan
    Hi everyone, I am experiencing a problem that has popped up recently and is causing quite a bit of trouble for our system. The app we have relies on using the movedown method to organize content, but as of late it has stopped working and began to generate the following warning: Warning (2): array_values() [<a href='function.array-values'>function.array-values</a>]: The argument should be an array in [/usr/local/home/cake/cake_0_2_9/cake/libs/model/behaviors/tree.php, line 459] The line being referenced: list($node) = array_values($Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $id), 'fields' => array($Model->primaryKey, $left, $right, $parent), 'recursive' => $recursive ))); The line calling the method: $this->movedown($id,abs((int)$position)); I have exhausted every idea I could come up with. Has anyone else crossed this issue before? Any help, or pointing in a direction would be much appreciated!

    Read the article

  • Java : Count even values in a Binary Search Tree recursively

    - by user307682
    Hi, I need to find out how many even values are contained in a binary tree. this is my code. private int countEven(BSTNode root){ if ((root == null)|| (root.value%2==1)) return 0; return 1+ countEven(root.left) + countEven(root.right); } this i just coded as i do not have a way to test this out. I'm not able to test it out at the moment but need an answer so badly. any help is deeply appreciated.

    Read the article

  • Generate syntax tree for simple math operations

    - by M28
    I am trying to generate a syntax tree, for a given string with simple math operators (+, -, *, /, and parenthesis). Given the string "1 + 2 * 3": It should return an array like this: ["+", [1, ["*", [2,3] ] ] ] I made a function to transform "1 + 2 * 3" in [1,"+",2,"*",3]. The problem is: I have no idea to give priority to certain operations. My code is: function isNumber(ch){ switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': return true; break; default: return false; break; } } function generateSyntaxTree(text){ if (typeof text != 'string') return []; var code = text.replace(new RegExp("[ \t\r\n\v\f]", "gm"), ""); var codeArray = []; var syntaxTree = []; // Put it in its on scope (function(){ var lastPos = 0; var wasNum = false; for (var i = 0; i < code.length; i++) { var cChar = code[i]; if (isNumber(cChar)) { if (!wasNum) { if (i != 0) { codeArray.push(code.slice(lastPos, i)); } lastPos = i; wasNum = true; } } else { if (wasNum) { var n = Number(code.slice(lastPos, i)); if (isNaN(n)) { throw new Error("Invalid Number"); return []; } else { codeArray.push(n); } wasNum = false; lastPos = i; } } } if (wasNum) { var n = Number(code.slice(lastPos, code.length)); if (isNaN(n)) { throw new Error("Invalid Number"); return []; } else { codeArray.push(n); } } })(); // At this moment, codeArray = [1,"+",2,"*",3] return syntaxTree; } alert('Returned: ' + generateSyntaxTree("1 + 2 * 3"));

    Read the article

  • How can a B-tree node be represented?

    - by chronodekar
    We're learning B-trees in class and have been asked to implement them in code. The teacher has left choice of programming language to us and I want to try and do it in C#. My problem is that the following structure is illegal in C#, unsafe struct BtreeNode { int key_num; // The number of keys in a node int[] key; // Array of keys bool leaf; // Is it a leaf node or not? BtreeNode*[] c; // Pointers to next nodes } Specifically, one is not allowed to create a pointer to point to the structure itself. Is there some work-around or alternate approach I could use? I'm fairly certain that there MUST be a way to do this within the managed code, but I can't figure it out. EDIT: Eric's answer pointed me in the right direction. Here's what I ended up using, class BtreeNode { public List<BtreeNode> children; // The child nodes public static int MinDeg; // The Minimum Degree of the tree public bool IsLeaf { get; set; } // Is the current node a leaf or not? public List<int> key; // The list of keys ... }

    Read the article

  • OutOfMemoryError creating a tree recursively?

    - by Alexander Khaos Greenstein
    root = new TreeNode(N); constructTree(N, root); private void constructTree(int N, TreeNode node) { if (N > 0) { node.setLeft(new TreeNode(N-1)); constructTree(N-1, node.getLeft()); } if (N > 1) { node.setMiddle(new TreeNode(N-2)); constructTree(N-2, node.getMiddle()); } if (N > 2) { node.setRight(new TreeNode(N-3)); constructTree(N-3, node.getRight()); } Assume N is the root number, and the three will create a left middle right node of N-1, N-2, N-3. EX: 5 / | \ 4 3 2 /|\ 3 2 1 etc. My GameNode class has the following variables: private int number; private GameNode left, middle, right; Whenever I construct a tree with an integer greater than 28, I get a OutOfMemoryError. Is my recursive method just incredibly inefficient or is this natural? Thanks!

    Read the article

  • How to reload Ext.tree.TreePanel on demand?

    - by Sergei Stolyarov
    I want to create Ext.tree.TreePanel component and periodically load content from the external URl. So I've written something like new Ext.tree.TreePanel({ root: { nodeType: 'async', text: 'asdasd', draggable: false, id: 'folders-tree-root' }, loader: new Ext.tree.TreeLoader() }); And now I want to reload this tree, so I write: tree.loader.dataUrl = 'folders-sample.json'; tree.root.reload(); And nothing happens. add: The only way I've found is set some invalid value to dataUrl param on TreeLoader creation: new Ext.tree.TreePanel({ root: { nodeType: 'async', text: 'asdasd', draggable: false, id: 'folders-tree-root' }, loader: new Ext.tree.TreeLoader(dataUrl: 'something') });

    Read the article

  • Binary Tree in C Insertion Error

    - by Paul
    I'm quite new to C and I'm trying to implement a Binary Tree in C which will store a number and a string and then print them off e.g. 1 : Bread 2 : WashingUpLiquid etc. The code I have so far is: #include <stdio.h> #include <stdlib.h> #define LENGTH 300 struct node { int data; char * definition; struct node *left; struct node *right; }; struct node *node_insert(struct node *p, int value, char * word); void print_preorder(struct node *p); int main(void) { int i = 0; int d = 0; char def[LENGTH]; struct node *root = NULL; for(i = 0; i < 2; i++) { printf("Please enter a number: \n"); scanf("%d", &d); printf("Please enter a definition for this word:\n"); scanf("%s", def); root = node_insert(root, d, def); printf("%s\n", def); } printf("preorder : "); print_preorder(root); printf("\n"); return 0; } struct node *node_insert(struct node *p, int value, char * word) { struct node *tmp_one = NULL; struct node *tmp_two = NULL; if(p == NULL) { p = (struct node *)malloc(sizeof(struct node)); p->data = value; p->definition = word; p->left = p->right = NULL; } else { tmp_one = p; while(tmp_one != NULL) { tmp_two = tmp_one; if(tmp_one->data > value) tmp_one = tmp_one->left; else tmp_one = tmp_one->right; } if(tmp_two->data > value) { tmp_two->left = (struct node *)malloc(sizeof(struct node)); tmp_two = tmp_two->left; tmp_two->data = value; tmp_two->definition = word; tmp_two->left = tmp_two->right = NULL; } else { tmp_two->right = (struct node *)malloc(sizeof(struct node)); tmp_two = tmp_two->right; tmp_two->data = value; tmp_two->definition = word; tmp_two->left = tmp_two->right = NULL; } } return(p); } void print_preorder(struct node *p) { if(p != NULL) { printf("%d : %s\n", p->data, p->definition); print_preorder(p->left); print_preorder(p->right); } } At the moment it seems to work for the ints but the description part only prints out for the last one entered. I assume it has something to do with pointers on the char array but I had no luck getting it to work. Any ideas or advice? Thanks

    Read the article

  • How-to read data from selected tree node

    - by Frank Nimphius
    Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} By default, the SelectionListener property of an ADF bound tree points to the makeCurrent method of the FacesCtrlHierBinding class in ADF to synchronize the current row in the ADF binding layer with the selected tree node. To customize the selection behavior, or just to read the selected node value in Java, you override the default configuration with an EL string pointing to a managed bean method property. In the following I show how you change the selection listener while preserving the default ADF selection behavior. To change the SelectionListener, select the tree component in the Structure Window and open the Oracle JDeveloper Property Inspector. From the context menu, select the Edit option to create a new listener method in a new or an existing managed bean. Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} For this example, I created a new managed bean. On tree node select, the managed bean code prints the selected tree node value(s) import java.util.List; import javax.el.ELContext; import javax.el.ExpressionFactory; import javax.el.MethodExpression; import javax.faces.application.Application; import javax.faces.context.FacesContext; import java.util.Iterator; import oracle.adf.view.rich.component.rich.data.RichTree; import oracle.jbo.Row; import oracle.jbo.uicli.binding.JUCtrlHierBinding; import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding; import org.apache.myfaces.trinidad.event.SelectionEvent; import org.apache.myfaces.trinidad.model.CollectionModel; import org.apache.myfaces.trinidad.model.RowKeySet; import org.apache.myfaces.trinidad.model.TreeModel; public class TreeSampleBean { public TreeSampleBean() {} public void onTreeSelect(SelectionEvent selectionEvent) { //original selection listener set by ADF //#{bindings.allDepartments.treeModel.makeCurrent} String adfSelectionListener = "#{bindings.allDepartments.treeModel.makeCurrent}";   //make sure the default selection listener functionality is //preserved. you don't need to do this for multi select trees //as the ADF binding only supports single current row selection     /* START PRESERVER DEFAULT ADF SELECT BEHAVIOR */ FacesContext fctx = FacesContext.getCurrentInstance(); Application application = fctx.getApplication(); ELContext elCtx = fctx.getELContext(); ExpressionFactory exprFactory = application.getExpressionFactory();   MethodExpression me = null;   me = exprFactory.createMethodExpression(elCtx, adfSelectionListener,                                           Object.class, newClass[]{SelectionEvent.class});   me.invoke(elCtx, new Object[] { selectionEvent });     /* END PRESERVER DEFAULT ADF SELECT BEHAVIOR */   RichTree tree = (RichTree)selectionEvent.getSource(); TreeModel model = (TreeModel)tree.getValue();  //get selected nodes RowKeySet rowKeySet = selectionEvent.getAddedSet();   Iterator rksIterator = rowKeySet.iterator();   //for single select configurations,this only is called once   while (rksIterator.hasNext()) {     List key = (List)rksIterator.next();     JUCtrlHierBinding treeBinding = null;     CollectionModel collectionModel = (CollectionModel)tree.getValue();     treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();     JUCtrlHierNodeBinding nodeBinding = null;     nodeBinding = treeBinding.findNodeByKeyPath(key);     Row rw = nodeBinding.getRow();     //print first row attribute. Note that in a tree you have to     //determine the node type if you want to select node attributes     //by name and not index      String rowType = rw.getStructureDef().getDefName();       if(rowType.equalsIgnoreCase("DepartmentsView")){      System.out.println("This row is a department: " +                          rw.getAttribute("DepartmentId"));     }     else if(rowType.equalsIgnoreCase("EmployeesView")){      System.out.println("This row is an employee: " +                          rw.getAttribute("EmployeeId"));     }        else{       System.out.println("Huh????");     }     // ... do more useful stuff here   } } -------------------- Download JDeveloper 11.1.2.1 Sample Workspace

    Read the article

  • Find all paths from root to leaves of tree in Scheme

    - by grifaton
    Given a tree, I want to find the paths from the root to each leaf. So, for this tree: D / B / \ A E \ C-F-G has the following paths from root (A) to leaves (D, E, G): (A B D), (A B E), (A C F G) If I represent the tree above as (A (B D E) (C (F G))) then the function g does the trick: (define (g tree) (cond ((empty? tree) '()) ((pair? tree) (map (lambda (path) (if (pair? path) (cons (car tree) path) (cons (car tree) (list path)))) (map2 g (cdr tree)))) (else (list tree)))) (define (map2 fn lst) (if (empty? lst) '() (append (fn (car lst)) (map2 fn (cdr lst))))) But this looks all wrong. I've not had to do this kind of thinking for a while, but I feel there should be a neater way of doing it. Any ideas for a better solution (in any language) would be appreciated.

    Read the article

  • How to reduce redundant code when adding new c++0x rvalue reference operator overloads

    - by Inverse
    I am adding new operator overloads to take advantage of c++0x rvalue references, and I feel like I'm producing a lot of redundant code. I have a class, tree, that holds a tree of algebraic operations on double values. Here is an example use case: tree x = 1.23; tree y = 8.19; tree z = (x + y)/67.31 - 3.15*y; ... std::cout << z; // prints "(1.23 + 8.19)/67.31 - 3.15*8.19" For each binary operation (like plus), each side can be either an lvalue tree, rvalue tree, or double. This results in 8 overloads for each binary operation: // core rvalue overloads for plus: tree operator +(const tree& a, const tree& b); tree operator +(const tree& a, tree&& b); tree operator +(tree&& a, const tree& b); tree operator +(tree&& a, tree&& b); // cast and forward cases: tree operator +(const tree& a, double b) { return a + tree(b); } tree operator +(double a, const tree& b) { return tree(a) + b; } tree operator +(tree&& a, double b) { return std::move(a) + tree(b); } tree operator +(double a, tree&& b) { return tree(a) + std::move(b); } // 8 more overloads for minus // 8 more overloads for multiply // 8 more overloads for divide // etc which also has to be repeated in a way for each binary operation (minus, multiply, divide, etc). As you can see, there are really only 4 functions I actually need to write; the other 4 can cast and forward to the core cases. Do you have any suggestions for reducing the size of this code? PS: The class is actually more complex than just a tree of doubles. Reducing copies does dramatically improve performance of my project. So, the rvalue overloads are worthwhile for me, even with the extra code. I have a suspicion that there might be a way to template away the "cast and forward" cases above, but I can't seem to think of anything.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >