Implementing BST in C ( header file )

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]

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]

Representing Arrays as a class in cpp

Program to implement an array.(Source Code) // Program Ch02pr01 // Program to implement an array. #include using namespace std; const int MAX \= 100 ; class array { private : int arrMAXMAX ; int N; int pos; public : void create(int i) { N\=i; int arrNN; pos\=0; } void add(int n); void insert ( int pos, int num) ; void del ( int pos ) ; void reverse( ) ; void display( ) ; void search ( int num ) ; } ; void array::add(int n) { arrpos++pos++\=n; } // inserts an element num at given position pos void array :: insert ( int pos, int num ) { // shift elements to right int i; for ( i \= N \- 1 ; i &gt;\= pos ; i\-\- ) { arrii \= arr\[i \- 1\] ; } arrii \= num ; } // deletes an element from the given position pos void array :: del ( int pos ) { // skip to the desired position int i; for ( i \= pos ; i &lt; N ; i++ ) arr\[i \- 1\] \= arrii ; arr\[i \- 1\] \= 0 ; } // reverses the entire array void array :: reverse( ) { for ( int i \= 0 ; i &lt; N / 2 ; i++ ) { int temp \= arrii ; arrii \= arr\[N \- 1 \- i\] ; arr\[N \- 1 \- i\] \= temp ; } } // searches array for a given element num void array :: search ( int num ) { // Traverse the array int i; for ( i \= 0 ; i &lt; N ; i++ ) { if ( arrii \=\= num ) { cout &lt;&lt; "\\n\\nThe element " &lt;&lt; num &lt;&lt; " is present at "&lt;&lt; ( i + 1 ) &lt;&lt; "th position" ; return ; } } if ( i \=\= N ) cout &lt;&lt; "\\n\\nThe element " &lt;&lt; num &lt;&lt; " is not present in the array" ; } // displays the contents of a array void array :: display( ) { cout&lt;&lt; endl ; // traverse the entire array for ( int i \= 0 ; i &lt; N ; i++ ) cout &lt;&lt; " " &lt;&lt; arrii ; } int main( ) { array a ; a. [Read More]