LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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 GCentral
What does "Engineering Redefined" mean??
Message 11 of 40
(1,751 Views)

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!
0 Kudos
Message 12 of 40
(1,729 Views)

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 GCentral
What does "Engineering Redefined" mean??
Message 13 of 40
(1,719 Views)

... 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 GCentral
What does "Engineering Redefined" mean??
Message 14 of 40
(1,708 Views)

a different solution....

Example_VI.png

0 Kudos
Message 15 of 40
(1,701 Views)

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 GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 16 of 40
(1,694 Views)

because it is not an integer32...

0 Kudos
Message 17 of 40
(1,687 Views)

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 GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 18 of 40
(1,684 Views)

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

 

sorry for the hijack...

0 Kudos
Message 19 of 40
(1,672 Views)

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

0 Kudos
Message 20 of 40
(1,660 Views)