Note
The primary goal is to explain concepts rather than focusing on implementation details. Therefore, we aren't using setters and getters to access class data members. This approach keeps the code concise and directs attention to the core ideas being discussed.
-
Class name should be written in PascalCase
class LinkedList
-
for class or function templates, use the
typenamekeyword instead ofclasskeywordDo:
template <typename T> ..
Don't:
template <class T> ..
-
functions and variable names should be written in camelCase
-
consider using
constwhenever applicable especially for member functions that don't modify the objectvoid isEmpty() const; int newData;
-
Clearly separate type name from variable name, pointer () and reference (&) type designators are to be placed next to the type name without any whitespace. Variable names should be then placed after a whitespace. ()
Do:
int* ptr; int& value;
Don't
int *ptr; int &value;
-
Pointers' names should end with ptr to make it clear
Node* headPtr; Node* frontPtr;
-
opening braces should be placed on a new line
Do:
function { //function body }Don't
function{ //function body }
- Use of
nullptris preferred overNULLto adhere to modern C++ practices - Avoid
using namespace std
-
Avoid using Hungarian notation: As the C++ Core Guidelines strongly discourage the use of Hungarian method. The guidelines advocate for using clear and descriptive names that reflect the purpose of variables and functions without relying on prefixes to convey their types as in semantic naming.
examples:
//Hungarian notation // Old variable name string txtTextBox // TextBox string frmInputForm // InputForm
Also check: