# C++ Programming Code Examples

## Learn C++ Language

### bar() Function in C++ Programming Language

**bar() Function in C++**

**Syntax for bar() Function in C++**

#include <graphics.h>
void bar(int left, int top, int right, int bottom);

left

X coordinate of top left corner.
top

Y coordinate of top left corner.
right

X coordinate of bottom right corner.
bottom

Y coordinate of bottom right corner.
Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color use setfillstyle.
This function does not return any value.
/* The bar() function is used to draw a bar ( of bar graph) which is a 2-dimensional figure. It is filled rectangular figure. The function takes four arguments that are the coordinates of (X, Y) coordinates of the top-left corner of the bar {left and top } and (X, Y) coordinates of the bottom-right corner of the bar {right and bottom}.
*/
/* draw a filled-in, rectangular, two-dimensional bar by bar() function code example. */
#include <graphics.h>
// driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd = DETECT, gm;
// initgraph initializes the
// graphics system by loading a
// graphics driver from disk
initgraph(&gd, &gm, "");
// location of sides
int left, top, right, bottom;
// left, top, right, bottom denotes
// location of rectangular bar
bar(left = 150, top = 150,
right = 190, bottom = 350);
bar(left = 220, top = 250,
right = 260, bottom = 350);
bar(left = 290, top = 200,
right = 330, bottom = 350);
// y axis line
line(100, 50, 100, 350);
// x axis line
line(100, 350, 400, 350);
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system .
closegraph();
return 0;
}

This C++ program, displays the traversal of a "binary search tree" in inorder,postorder and preorder mode using "Linked Lists". A linked list is an ordered set of 'data elements', each

Insertion sort is simple sorting algorithm that builds the final sorted array ('or list') one item at a time. It is much less efficient on large lists than more advanced algorithms such as quick

In case of 'an array' we check that a given key or a number is present in array at any index or not by "comparing each element" of array. By traversing the whole data structure elements