# LabVIEW

cancel
Showing results for
Did you mean:

## Re: How to sort an array in Even and odd parts

@Ranjeet_Singh wrote:
Using local variable is not a crime.

Nothing to do with local variables.

It is almost a crime to give a new student horribly complicated advice if, as in this case, much better, simpler and cleaner solutions exist. Soon the students thinks that LabVIEW is way too hard and give up.

Show them a concise, efficient and easy to understand solution and they will appreciate the beauty and simplicty of LabVIEW and will be happy to learn more. LabVIEW is fun!

You don't teach a little kid how to walk by leading it into a swamp. Too many alligators! 😄

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 11 of 40
(1,751 Views)

## Re: How to sort an array in Even and odd parts

In this case indexing the output using the conditional mode (LV2012 and later) can be very useful...

Ben64

--------------------------------------------------
The best way to say thanks is to give kudos!
Message 12 of 40
(1,729 Views)

## Re: How to sort an array in Even and odd parts

Sometimes it is OK to show a more complicated alternative solution to teach some useful techniques. Here is one such solution. 😄

Try to understand the exact reason for each of the operations shown (maybe the discussion in this idea can give you some clues because with the idea implemented, we could do a completely loop-free solution :D). Also try to figure out why we need the case structure (and if you cannot load the snippet, what is contained in the other case ;)).

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 13 of 40
(1,719 Views)

## Re: How to sort an array in Even and odd parts

... and here is a version that does not use any loops at all 😄 Explain how it works!

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 14 of 40
(1,708 Views)

## Re: How to sort an array in Even and odd parts

a different solution....

Message 15 of 40
(1,701 Views)

## Re: How to sort an array in Even and odd parts

Yes, the obvious solution, except that a case structure would cut the number of array operations in half.

However these corcion dots on the bitwise operation make me cringe. Do you know why they are there? 😄

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 16 of 40
(1,694 Views)

## Re: How to sort an array in Even and odd parts

because it is not an integer32...

Message 17 of 40
(1,687 Views)

## Re: How to sort an array in Even and odd parts

Probably the most efficient way would be to operate on the original array in place in a shift register and going through it from both ends at once similar to the "quickselect" algorithm. Instead of using a pivot value we select between even and odd and swap misplaced elements pairwise until the indices meet, followed by an array split as shown in my earlier code.

Would be an interesting exercise. 😄 I remember writing an efficient implementation in the old median challenge that could be re-used with minor changes. (Cannot find the link. Were are these discussions???)

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 18 of 40
(1,684 Views)

## Re: How to sort an array in Even and odd parts

does it have something to do with memory use for efficiency in that 'in place' was developed?

sorry for the hijack...

Message 19 of 40
(1,672 Views)

## Re: How to sort an array in Even and odd parts

Yes, see here.   This omits the allocation of a few bytes which sum up in the long run ...

Message 20 of 40
(1,660 Views)