RE: Source Code of Some Well Known Algorithms 09-11-2013, 04:40 PM
#6
(09-11-2013, 03:51 PM)Slarek Wrote: Here's my contribution:
Challenge:Binary tree
Wikipedia: http://en.wikipedia.org/wiki/Binary_tree
Pastebin: http://pastebin.com/QzsK5Upm
Language: C/C++
Code:#include <stdio.h> #include <stdlib.h> #include <iostream.h> #include <classlib\binimp.h> #include <string.h> void print(string &s,void *os) { (ostream &)os << s << " "; } #define print_tree(cout,tree) { tree.ForEach(print,(void *)cout); cout << "\n"; } int main(void) { TBinarySearchTreeImp<string> tree; string s; char ss[10]; cout << "--------------------------------------------------------------\n"; for (int i=0; i<15; i++) { //Fill the tree with random strings sprintf(ss,"%03d",(rand() % 1000)); cout << ss << " "; tree.Add(ss); } cout << "\n"; cout << "--------------------------------------------------------------\n"; cout << "Content of the tree:\n"; print_tree(cout,tree); while (1) { cout << "Give a string and I'll check if it's in the tree >"; getline(cin,s,'\n'); if ( s == "" ) break; if ( tree.Find(s) ) { tree.Detach(s); cout << s << " It was in the tree, it got deleted!\n"; print_tree(cout,tree); } else cout << "Not in the tree!\n"; } return 0; }
Sorry But I can't include this as you have not implementred the methods for Binary tree. The standard methods that Binary Tree ADT has. You are using #include <classlib\binimp.h> which may not be available to all the users. We want that all the methods should be included within file and not use any external file. Even if you use any external file and want to include it in your coede then that code must be yours and not any copyrighted code.
I will include this in the rules. Please retry and thanks as you are the first to try to contribute.
This should help you out :- http://phoenix.goucher.edu/~kelliher/cs23/may07.html
![[Image: OilyCostlyEwe.gif]](http://fat.gfycat.com/OilyCostlyEwe.gif)


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)