10-19-2013 09:19 AM - edited 10-19-2013 09:44 AM
@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! 😄
10-19-2013 11:27 AM
10-19-2013 12:18 PM - edited 10-19-2013 12:21 PM
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 ;)).
10-19-2013 12:29 PM - edited 10-19-2013 12:30 PM
... and here is a version that does not use any loops at all 😄 Explain how it works!
10-19-2013 12:37 PM
a different solution....
10-19-2013 12:49 PM
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? 😄
10-19-2013 12:57 PM
because it is not an integer32...
10-19-2013 01:00 PM - edited 10-19-2013 01:02 PM
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???)
10-19-2013 01:14 PM - edited 10-19-2013 01:14 PM
does it have something to do with memory use for efficiency in that 'in place' was developed?
sorry for the hijack...
10-19-2013 01:28 PM
Yes, see here. This omits the allocation of a few bytes which sum up in the long run ...