write member function that counts number of nodes and number of leaves in binary search trees?
344099
class tree {\npublic:\n int countNodes(){\n    if (root == NULL) { return 0; }\n    return this.countNodes(root);\n }\nprivate:\n int countNodes(Node in){\n    if (in == NULL){ return 0; }\n    else { return countNodes(root->leftSubtree) + countNodes(root->rightSubtree) + 1; }\n }\nNode* root;\n};
483878
Refer to some site dood ... type "difference between difference alloc statements in C" in Y! Search
1123125
Function CountWords(strText As String) As Long\n   ' This procedure counts the number of words in a string.\n\n   Dim astrWords() As String\n\n   astrWords = Split(strText)\n   ' Count number of elements in array -- this will be the\n   ' number of words.\n   CountWords = UBound(astrWords) - LBound(astrWords) + 1\nEnd Function\n\nYou can modify above function to split using pipe delimiter.
817773
a  binary search works on the principle of the left node being smaller than the central node and the right node being larger than the central node..assuming the node i am searching for has the value 5 and the central node 2 levels up is 10\n\nso 10 can have two child nodes right node =14,left node =7\n7 can have two nodes =left node 5,right node 9\n\n\nwhat an index on a record file of variable length would do is assign a unique id to each record in that file,so when the binary search is going on to find a specific node,it will have to follow the lesser path or greater than central node path..so to find the lesser part it will have to determine the position of the next node ..this is done by indexing since all it has to do is to reference that unique id which will point it to the next node and so on...\n\n\nIf the records are not indexed it will not be able to determine which node exists hence will fail
363476
There's not enough information, what type of list, I don't think you mean an Enumerated List, and into what type of split, are you talking about linked lists, or something like indexing using trees to navigate or manage keys?
613322
It cannot be done automatically within a text editor, as there is no way for the test editor to count the lines, etc.\nOne way would be to use a programming language where you can input the file with the urls, and go through the file placing the keyword after x amount of lines. The file is then output with these keywords.\nA quick c++ example.\n#include <iostream>\n\nint main() {\n\n    using namespace std;\n\n    char cur_line[1000]; // assume line is no longer than 999 characters, the last character should be a null '&#92;0';\n    int count = 1;\n    while (cin.getline(cur_line, 1000)) {\n        cout << cur_line << '&#92;n';\n        if (count == 5) { // the fifth line\n            cout << "#break&#92;n"; // or whatever you want to include\n            count = 1; // reset the count\n        } else\n            count++; // increment the count;\n    }\n}\n\nif you compile this as insert.cpp, and have insert.exe, then call insert < <original_file> > <file_to_go_to>,\nie insert < index.html > index_2.html\nnote, the files cannot be the same.
654083
a declaration\n\nexample:\nint count; defines count as an integer
391107
USe the function "CountIF"\n\ne-mail me for more details
9135
Since the keys in a B-tree is sorted, just keep following the first (leftmost) subtree until a node has no leftmost subtree.  Then the smallest element in that node will be the minimum key.
447556
Look up "quicksort".\n\nIt fits very naturally into a recursive implementation\nand is also a very efficient sorting algorithm.\n\nI've included a link to the Solaris source for quicksort.\nIt is written in C (rather than C++).  It is somewhat\ncomplicated because it optimizes the sorting of\nshort sequences by switching to an insertion sort.\nHowever, you could implement a simpler version which\nran quicksort all the way to completion.
1070038
about 1000 on a simple tree times roughly the amount of trees in the world which is over a 100,000,000 making 100,000,000,000,000 leaves on earth
78294
I dont exctly remenber how to do it, but you should check out "tokens" \nYou can take a string and divide it in tokens, (you can set you own division point, in you case " ") That way you could easily count how many blanks in the text.\n\nHope it helps..
569087
see http://mathworld.wolfram.com/NaturalLogarithm.html
958876
A simple algorithm is to first take all n(n-1)/2 pairs of points. Each pair defines a line, count how many of the remaining points lie on the line. This will be a cubic algorithm in n, the number of points.\n\nA clever algorithm using sorting takes time O( n^2 log n). See the Sources.
89402
Code:\npublic class BTNode \n{\n    private Object data;\n    private BTNode left, right;\n    public BTNode(Object initialData, BTNode initialLeft, BTNode initialRight)\n        { \n            data = initialData;\n            left = initialLeft;\n            right = initialRight;\n        }\n    public BTNode()\n            { this(null, null, null); }\n    \n    public BTNode(Object newdata)\n            { this(newdata, null, null); }\n    \n    //NODE methods\n    public Object getData()                     //return and set data in node\n            {return data;}\n    \n    public void setData(Object data)\n            {this.data = data; }\n    \n    public BTNode getLeft()                 //return and set left child\n            {return left; }\n    \n    public void setLeft(BTNode left)\n            {this.left = left; }\n    \n    public BTNode getRight()                //return and set right child\n            {return right; }\n    \n    public void setRight(BTNode right)\n            {this.right = right; }\n    \n    public boolean isLeaf()                 //return true if this is leaf node\n            {return (left == null)&&(right == null); }\n \n// TREE Methods - for tree starting at this node\n// get specific data from a tree\n    \n        public Object getLeftmostData()\n        { if(left == null)\n               return data;\n          else \n              return left.getLeftmostData(); }\n        \n        public Object getRightmostData()\n              { if(right == null)\n               return data;\n          else \n              return right.getRightmostData(); }\n// print data in a tree\n        public void inorderPrint()\n                {\n                    if (left != null)\n                        left.inorderPrint( );\n                    System.out.print(data+"&#92;t");\n                    if (right != null)\n                        right.inorderPrint( ); }\n        \n        public void preorderPrint()\n                {\n                    System.out.print(data+"&#92;t");\n                    if (left != null)\n                        left.preorderPrint( );\n                    if (right != null)\n                        right.preorderPrint( ); }\n        \n        public void postorderPrint()\n                {\n                    if (left != null)\n                        left.postorderPrint( );\n                    if (right != null)\n                        right.postorderPrint( );\n                    System.out.print(data+"&#92;t"); }\n        \n// pretty print a tree\n        //public void print(int depth);\n \n//Interface for Nodes in Binary Tree (3)\n//removing nodes from a tree\n//returns reference to tree after removal of node\n        public BTNode removeLeftmost()\n              {\n                    if (left == null)                               // we are as deep as we can get\n                        return right;                               // remove this node by returning right subt ree\n                    else\n                        {                                           // keep going down recursively\n                            left = left.removeLeftmost( );\n                                                                    // when done, return node that act ivated this\n                                                                    // method as root of t ree\n                            return this; }}\n        \n        public BTNode removeRightmost()\n        {\n                    if (right == null)                               // we are as deep as we can get\n                        return left;                               // remove this node by returning left subt ree\n                    else\n                        {                                           // keep going down recursively\n                            right = right.removeRightmost( );\n
218696
There may be some good theory on this topic, but\nI'd like to point out one obvious solution and\none possibly-special-case solution.\n\nFirst, given a graph, if you have the ability to \ntraverse the entire graph and "mark" each node as\nyou visit it, then if you ever run into a marked\nnode, then there is a cycle.  The most obvious way\nto mark a node is to store a flag in it, but it\nis also possible to build a separate data structure\nto keep track of each node (ie. a hash table \nindexed by node address or something like that.)\n\nAnother trick I've seen used on lists, but *might* be\ngeneralized to some more-complicated graphs, is the\nidea of a follow-pointer.  In the case of a list,\nthe "follow pointer" traverses one list link\nfor every *two* that the real traversal covers.\nIf there is a loop in the list, eventually the\n"lead" pointer will wrap around and catch up\nto the "follow" pointer.  Thus, you know that\nthere's a cycle if the two pointers ever refer\nto the same node.
1116199
the only time you would need Trees is if your a programer then you would you use tree methods