Iterative postorder traversal in BST code in c

As far we have seen iterative inorder traversal in BST using stack. Most traversal are solved using stack in BST. Here iterative postorder traversal in BST also implemented using 2 stacks.

Approach :

Two stacks S1 & S2 

Stack2 (S2) is used only for output purpose only

step 1: push the root in  Stack S1

step2: pop the element from s1  and mark as current node then push into S2

step 3: if popped element has left element then push it into s1

step 4: if popped element has right element then push it into s1

step 5: Follow from step2 to step4 untill stack s1 is emply.

Step 6: Pop out and print the all element from s2


Function for iterative postorder traversal :


Complete C implementation with BST implementation and iterative postorder traversal  function


C code to implement myatoi function


implementation of myatoi function in c.

Atoi function converts a string numeric value into integer value.



C code to reverse words in place in a string

C program to reverse words in place in a string:

Approach :

Step1: Reverse the whole string

Step2: Reverse the characters in words


Before Rev Old: [I am a good coder]

After Rev: [redoc doog a ma I]

New: [coder good a am I]




Calculating Factorial of large numbers in c

As we all know there is memory limitation in C. If we want to store number which is more than of 4 byte we cannot use int data type. We can use long data type to store value which is upto 8 byte. What after that?. If our value is of more than 8 bytes then we have to implement our own method to store value.

Here is the implementation of calculating factorial for large numbers like 100!


This program works on basic method of multiplication of a two numbers.


X 15

Ans: 18510

Steps are:

Step                                       Digit                       Carry

15*4 = 60;                            0                              6

(15*3)+6=51                       1                              5

(15*2)+5=35                       5                              3

(15*1)+3=18                       8                              1

After this carry digits are extracted and stored in array.  ( if our carry was 25 then we must extract 2 and 5 then store it in array )

So output is: 18510

In program:

Array of 200 lengths is taken to store digits of multiplication result.

Index variable indicates the length of output..

tmp is used to store carry value;


Calculating Factorial of large numbers in c

Her we have taken array size of 200 so we can calculate factorial of a number whose digits are 200. if you want to calculate for more than 200 just increase the size of array.



C program to mirror binary tree

C function to mirror binary tree.



C Function implementation :


Complete C Code implementation


Print Ancestor of given node value in binary tree

Print Ancestor of given node value in binary tree.

For Given Binary Search tree find out the ancestor of a given node value .

Binary Search Tree , 8 is root node ,left branch has nodes whose value are less than 8 and right branch has nodes whose values are greater than 8
Binary Search Tree


Node Value                O/P

4                                    8  3  6

13                                8  10  14


Recursive function to print ancestor values for given binary search tree.


Complete code with binary search tree implementation and ancestor printing function.



C Code Examples

C code to perform operation on array and basic input output of int, float, char, string in c.

Basic I/O Array Operation
Integer  input Array input
Float input Array Sorting
Char input   >Basic Method
String input   >Bubble Sort
  >Insertion Sort
  >Quick Sort
  >Heap Sort

Star pattern printing using C code. :

C code examples to pattern printing using stars and string function implementation to perform string manipulations.

Star printing patterns in C.                           String function implementation.

Aeroplane pattern printing using stars  Copy string into another (cstrcpy)
Pyramid pattern printing using stars  Calculate length of a string (cstrlen)
Rev pyramid printing using stars  Sub string from a string (csubstr)
Diamond pattern printing using stars  Compare strings  (cstrcmp)
Triangle pattern printing using stars


C Code Examples to play with numbers.

Find a perfect number Print Pascal Triangle
Find a factorial of a number  Fibonacci series


Specific level printing in BST

C code to print specific level values in BST. Level 0 mean Root value.



For above binary tree
Level          Values

0                       8

1                      3  10

2                     1   6  14


Function implementation for level printing :



Complete C code with implementation of binary tree and level printing in BST.



Binary Tree implementation with print all paths

Binary Tree implementation code with print all paths in Binary tree Code in C.