Another interesting approach can be to create a binary search tree but
with a different logic:

Left subtree will have values greater than root and right subtree will
have values lesser than root.Here root will be 1,the very first array
element.

Now traverse the tree in pre-order to get the desired output.

The only problem with the method is it requires extra space !!!

Regards,
Ashish

On Jun 27, 6:18 am, Dave <[email protected]> wrote:
> j = 0
> for i = 1 to n
>     if a(i) not equal 0
>         j = j + 1
>         a(j) = a(i)
>     end if
> end for
> for i = j + 1 to n
>     a(i) = 0
> end for
>
> Dave
>
> On Jun 26, 3:27 pm, jalaj jaiswal <[email protected]> wrote:
>
> > Given an array of integers, {1,0,2,0,3,0,0,4,5,6,7,0,0,0}, you have to
> > create a new array which will be like (1,2,3,4,5,6,7,0,0,0,0,0,0,0}, without
> > using any other temporary array.
>
> > --
> > With Regards,
> > Jalaj Jaiswal
> > +919026283397
> > B.TECH IT
> > IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to