Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Shortening main.cpp
Move all the template functions into either bintree.h or bintree.template. Templates are for generic use and really shouldn't be in the file where you are using them. Perhaps make the template functions in main.cpp part of your binary tree class.

using namespace std;
Namespaces were invented to prevent the collision of function names from different sources. The code contains a specific namespace, main_savitch_10. Within main_savitch_10 std:: is actually used. It would be less confusing to anyone that had to maintain this code if the namespaces were fully specified within all the code. Take a look at this question on StackOverflow question on StackOverflow.

This is especially true in your function balanced_tree_rec(), this would be a lot more readable and maintainable if it was declared

binary_tree_node<int>* balanced_tree_rec(std::list<Item>* list,Item count)

Global Variables
The use of global variables is generally frowned on. There may be a few valid uses of them, but the use of global variables within a template function is not portable and not maintainable. It effectively breaks the template function.

list<int>* item_list = new list<int>;
list<int>* item_list2 = new list<int>;
list<int>* temp2 = new list<int>;

template binary_tree_node* balanced_tree_rec(list* list,Item count)

 temp2 = list;
 temp2 -> pop_front();

template void push(Item& test)

 item_list2 -> push_back(test);

Use Meaningful Names
Quite often in the software development world, others have to maintain the code we write, variable names and function names should clearly indicate what they are some examples that would be a problem are BBST(), list, p, and a;

Standard File Extensions
There are several discussions on Stack Overflow about the proper extension for a template file, you might want to look at these (convention convention, extension extension and templates templates). I personally would either add it within the name space section of bintree.h or create a bintree.hpp. The boost libraries use hpp. The reason I would combine both files into one is that the template file by itself won't compile without the bintree.h.

Shortening main.cpp
Move all the template functions into either bintree.h or bintree.template. Templates are for generic use and really shouldn't be in the file where you are using them. Perhaps make the template functions in main.cpp part of your binary tree class.

using namespace std;
Namespaces were invented to prevent the collision of function names from different sources. The code contains a specific namespace, main_savitch_10. Within main_savitch_10 std:: is actually used. It would be less confusing to anyone that had to maintain this code if the namespaces were fully specified within all the code. Take a look at this question on StackOverflow.

This is especially true in your function balanced_tree_rec(), this would be a lot more readable and maintainable if it was declared

binary_tree_node<int>* balanced_tree_rec(std::list<Item>* list,Item count)

Global Variables
The use of global variables is generally frowned on. There may be a few valid uses of them, but the use of global variables within a template function is not portable and not maintainable. It effectively breaks the template function.

list<int>* item_list = new list<int>;
list<int>* item_list2 = new list<int>;
list<int>* temp2 = new list<int>;

template binary_tree_node* balanced_tree_rec(list* list,Item count)

 temp2 = list;
 temp2 -> pop_front();

template void push(Item& test)

 item_list2 -> push_back(test);

Use Meaningful Names
Quite often in the software development world, others have to maintain the code we write, variable names and function names should clearly indicate what they are some examples that would be a problem are BBST(), list, p, and a;

Standard File Extensions
There are several discussions on Stack Overflow about the proper extension for a template file, you might want to look at these (convention, extension and templates). I personally would either add it within the name space section of bintree.h or create a bintree.hpp. The boost libraries use hpp. The reason I would combine both files into one is that the template file by itself won't compile without the bintree.h.

Shortening main.cpp
Move all the template functions into either bintree.h or bintree.template. Templates are for generic use and really shouldn't be in the file where you are using them. Perhaps make the template functions in main.cpp part of your binary tree class.

using namespace std;
Namespaces were invented to prevent the collision of function names from different sources. The code contains a specific namespace, main_savitch_10. Within main_savitch_10 std:: is actually used. It would be less confusing to anyone that had to maintain this code if the namespaces were fully specified within all the code. Take a look at this question on StackOverflow.

This is especially true in your function balanced_tree_rec(), this would be a lot more readable and maintainable if it was declared

binary_tree_node<int>* balanced_tree_rec(std::list<Item>* list,Item count)

Global Variables
The use of global variables is generally frowned on. There may be a few valid uses of them, but the use of global variables within a template function is not portable and not maintainable. It effectively breaks the template function.

list<int>* item_list = new list<int>;
list<int>* item_list2 = new list<int>;
list<int>* temp2 = new list<int>;

template binary_tree_node* balanced_tree_rec(list* list,Item count)

 temp2 = list;
 temp2 -> pop_front();

template void push(Item& test)

 item_list2 -> push_back(test);

Use Meaningful Names
Quite often in the software development world, others have to maintain the code we write, variable names and function names should clearly indicate what they are some examples that would be a problem are BBST(), list, p, and a;

Standard File Extensions
There are several discussions on Stack Overflow about the proper extension for a template file, you might want to look at these (convention, extension and templates). I personally would either add it within the name space section of bintree.h or create a bintree.hpp. The boost libraries use hpp. The reason I would combine both files into one is that the template file by itself won't compile without the bintree.h.

Source Link
pacmaninbw
  • 26.2k
  • 13
  • 47
  • 113

Shortening main.cpp
Move all the template functions into either bintree.h or bintree.template. Templates are for generic use and really shouldn't be in the file where you are using them. Perhaps make the template functions in main.cpp part of your binary tree class.

using namespace std;
Namespaces were invented to prevent the collision of function names from different sources. The code contains a specific namespace, main_savitch_10. Within main_savitch_10 std:: is actually used. It would be less confusing to anyone that had to maintain this code if the namespaces were fully specified within all the code. Take a look at this question on StackOverflow.

This is especially true in your function balanced_tree_rec(), this would be a lot more readable and maintainable if it was declared

binary_tree_node<int>* balanced_tree_rec(std::list<Item>* list,Item count)

Global Variables
The use of global variables is generally frowned on. There may be a few valid uses of them, but the use of global variables within a template function is not portable and not maintainable. It effectively breaks the template function.

list<int>* item_list = new list<int>;
list<int>* item_list2 = new list<int>;
list<int>* temp2 = new list<int>;

template binary_tree_node* balanced_tree_rec(list* list,Item count)

 temp2 = list;
 temp2 -> pop_front();

template void push(Item& test)

 item_list2 -> push_back(test);

Use Meaningful Names
Quite often in the software development world, others have to maintain the code we write, variable names and function names should clearly indicate what they are some examples that would be a problem are BBST(), list, p, and a;

Standard File Extensions
There are several discussions on Stack Overflow about the proper extension for a template file, you might want to look at these (convention, extension and templates). I personally would either add it within the name space section of bintree.h or create a bintree.hpp. The boost libraries use hpp. The reason I would combine both files into one is that the template file by itself won't compile without the bintree.h.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /