This post contains header file which contains binary search tree related function. The tree contains following functions:
Search Create new node Get the size of tree Insert Delete Print inorder, pre order and post order Starting the header file: Lets name our header file as Tree1.h.
#ifndef TREE1\_H #define TREE1\_H #include <stdio.h> #include <malloc.h> enum BOOL{false,true}; struct node { int data; struct node\* left; struct node\* right; } ; typedef struct node node; typedef enum BOOL BOOL; Defining some functions via c macros:
[Read More]
Initialising arrays
Conside the 2D arrays:
int anArray1[2][3] = {7};
`int anArray2[3][5] =
{
{ 1, 2, 3, 4, 5, }, // row 0
{ 6, 7, 8, 9, 10, }, // row 1
{ 11, 12, 13, 14, 15 } // row 2
};
int anArray3[][5] =
{
{ 1, 2, 3, 4, 5, },
{ 6, 7, 8, 9, 10, },
{ 11, 12, 13, 14, 15 }
};`
[Read More]
Multi-dimensional arrays
#include
#include
int main() {
int a[3][3][3][3];
//it gives address of a[0][0][0][0] .
printf(” \n address of array a is %u”, a);
printf("\n address of a[2][0][0][0] is %u , "
“given by a[2] , %u given by a+2”,
a[2], a + 2);
printf("\n address of a[2][2][0][0] is %u , "
“given by a[2][2] , %u given by a[2]+2”,
a[2][2], a[2] + 2);
printf("\n address of a[2][2][1][0] is %u , "
[Read More]
String Class in cpp(Standard cpp strings)
Here is how to test the string class already present in cpp.
To use simple strings u have to include . For example consider the program,
#include #include <conio.h>
using namespace std;
int main()
{
string word="hello”;
cout«word;
getch();
}
There are various functions and operators in this string class. These operators are present in string -
= assignment
+ , += concatenation etc
== , != . < , <= , >= , > equality etc.
[Read More]
Stack ADT
Stacks are an elementary Data Structure where all interaction with the data is done through the looking at the first element. Stacks are last in first out (LIFO) data structures. It is named on the basis of how the elements are removed from it. Opposite to stack is queue, in which the last element is removed, the element which was most old item, and hence it is FIFO or first in first out data structure.
[Read More]
Miscellaneous cases with printf
**Strings
**
1. printf(5+Fascimile);
O
mile
2. printf(5+"Good Morning”);
O
Morning
3. printf("%c”, abcdefg[4]);
O.
e
Strings
static char s[]= “Oinks Grunts and Guffaws”;
Now we see some results on this string:
1. *(&s[2])=s[2]=*(s+2)=*(2+s ) = n
2. strlen(s) = length of the string
so strlen(s)+s= last character of the string = \0 , whose ascii value is 0.
So when %c is used , \0 is printed and when %d is used 0 is printed.
3. when is printed with %d we get the base address of the string.
[Read More]
Method Overriding
Suppose bc and dc have same functions:
In case of java for eg.
Method overriding occurs only when the names and the type signatures of the two
methods are identical. If they are not, then the two methods are simply overloaded. For
example, consider this modified version of the preceding example:
// Methods with differing type signatures are overloaded – not overridden.
class A {
int i, j;
A(int a, int b) {
[Read More]
Access specification
This topic tells when is contructor called and when not
1.formation of object(lolz)
**
2.passing objects to the function**
class X
{
int i;
public:
X(int b){ cout«"love”; i=b; }
void set_i(int b){s=b;}
put_i() { cout«"i="<_<_ _}
X()//destructor { cout«"hate” }
}; // class over
void f(X ob)
{
ob.set_i(2);//i is now 2
ob.put_i();
}
int main()
{
X o(1);//i is 1
o.put_i();
f(o);//i is now 2
o.put_i();
return 0;
[Read More]
Access in cpp classes
When a base class is inherited as private, all public and protected members of that class
become private members of the derived class. However, in certain circumstances, you
may want to restore one or more inherited members to their original access
specification. For example, **you might want to grant certain public members of the base
class public status in the derived class even though the base class is inherited as private.
[Read More]