Tyrique  Littel

Tyrique Littel


A Template Tree Class in C++

In C++ you can create a templated class for generic trees that work with arbitrary data types. You may need to implement optimized trees for some use cases where performance is critical, but when you only need a random tree somewhere, it’s great to have a generic templated tree class available.

One of the most common data structures in computer science and programming is a tree. Trees are an abstract data type for all kinds of hierarchical data like file systems, parse trees, domain object models (HTML, XML), binary search trees, and many more.

Yet, there is no tree type in the C++ standard library.

Luckily, it’s not that difficult to create a tree data structure yourself. After creating many different trees for several projects over the years, I finally implemented a proper tree class with templates to make it work with arbitrary types.

#data-structures #cplusplus #programming #data-science

What is GEEK

Buddha Community

A Template Tree Class in C++

Represent Tree using graphics in C/C++

Prerequisite: graphics.hHow to include graphics.h?

In C/C++ there is graphics.h header file which is used to create the object like line, circle, etc.

Given an array arr[] of N integers, the task is to write C++ program to create the Tree using graphics.h.

Approach: To run the program we have the include the below header file:


We will create a Tree with the help below functions:

  1. setcolor(color): This function present in graphic.h header file which is used to set the current drawing color to the new color.
  2. floodfill(pattern, color): function is used to fill an enclosed area. The current fill pattern and fill color is used to fill the area.
  3. circle(x, y, radius): The header file graphics.h contains circle() function which draws a circle with center at (x, y) and given radius.
  4. outtextxy(): The header file graphics.h contains outtextxy() function which displays the text or string at a specified point (x, y) on the screen.

#computer-graphics #trees #c #c++ #cplusplus #programming-c

Tamale  Moses

Tamale Moses


How to Run C/C++ in Sublime Text?

C and C++ are the most powerful programming language in the world. Most of the super fast and complex libraries and algorithms are written in C or C++. Most powerful Kernel programs are also written in C. So, there is no way to skip it.

In programming competitions, most programmers prefer to write code in C or C++. Tourist is considered the worlds top programming contestant of all ages who write code in C++.

During programming competitions, programmers prefer to use a lightweight editor to focus on coding and algorithm designing. VimSublime Text, and Notepad++ are the most common editors for us. Apart from the competition, many software developers and professionals love to use Sublime Text just because of its flexibility.

I have discussed the steps we need to complete in this blog post before running a C/C++ code in Sublime Text. We will take the inputs from an input file and print outputs to an output file without using freopen file related functions in C/C++.

#cpp #c #c-programming #sublimetext #c++ #c/c++

Dicey Issues in C/C++

If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends. The following displays some of the issues:

  1. Using multiple variables in the print function
  2. Comparing Signed integer with unsigned integer
  3. Putting a semicolon at the end of the loop statement
  4. C preprocessor doesn’t need a semicolon
  5. Size of the string matters
  6. Macros and equations aren’t good friends
  7. Never compare Floating data type with double data type
  8. Arrays have a boundary
  9. Character constants are different from string literals
  10. Difference between single(=) and double(==) equal signs.

The below code generates no error since a print function can take any number of inputs but creates a mismatch with the variables. The print function is used to display characters, strings, integers, float, octal, and hexadecimal values onto the output screen. The format specifier is used to display the value of a variable.

  1. %d indicates Integer Format Specifier
  2. %f indicates Float Format Specifier
  3. %c indicates Character Format Specifier
  4. %s indicates String Format Specifier
  5. %u indicates Unsigned Integer Format Specifier
  6. %ld indicates Long Int Format Specifier

Image for post

A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a non-negative integer in the range [0 to 4294967295]. The signed integer is represented in twos-complement notation. In the below code the signed integer will be converted to the maximum unsigned integer then compared with the unsigned integer.

Image for post

#problems-with-c #dicey-issues-in-c #c-programming #c++ #c #cplusplus

Ari  Bogisich

Ari Bogisich


Classes and Objects in C++ | C++ Programming Language - Part2

This Edureka video Classes and Objects in C++ will help you to get started with C++. It will cover how to use classes and objects in C++.

#c #c# #c++ #programming-c

Hudson  Larkin

Hudson Larkin


C++ Templates Example | Template Class in C++

C++ templates are a simple yet powerful tool because the idea is to pass data type as the parameter so that we don’t need to write the same code for different data types.  Templates are the way of making your classes more abstract by letting you define the behavior of the class without actually knowing what the operations of the class will handle data type.

C++ Templates Example

Templates are the dominant features of C++, which allows you to write the generic programs. In simple terms, you can create a single  function or a class to work with different data types using templates.

Templates can be used in conjunction with abstract data types to allow them to handle any data. For example, you could make the templated stack class that can handle a stack of any data type, rather than having to create the stack class for every different datatype for which you want the stack to function.

A class template provides the specification for generating classes based on parameters. Class templates are generally used to implement the containers. A class template is instantiated by passing the given set of types to it as template arguments.

#c++ #c++ templates