LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

order a vector from highest to lowest using recursion

Solved!
Go to solution

good morning, I'm performing three Vi consisting of a main, and two sub VI, in the first sub VI the values are entered using a structure event in which every time the button is priced it stores the value in a vector, the next Sub VI takes that vector and sorts it from less than large, but this sub VI must have recursion to sort the vector, the vector entered in clutter and ordered is shown in the main VI. my drawback is that I don't know how to develop recursion maybe you can help me please. attached my files

0 Kudos
Message 1 of 14
(215 Views)

There is no need to use recursion for this unless this is a class assignment or homework. Can you clarify the purpose of this exercise?


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 2 of 14
(196 Views)

It's a Homework

0 Kudos
Message 3 of 14
(193 Views)
  • Your input VI makes no sense. The output can be generated instantly without any button or event structure. Also, since you initialize the shift register, you'll get each element twice in the output. Is this really what you want?
  • Seems you want to do a recursive bubble sort. As a first step, I would clean up the code. Seems excessively complicated. Both "index array" and "replace array subset" are resizeable, so you only need one instance each. (Personally, I would use the IPE structure, though). Why do you need two loops?

LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 4 of 14
(188 Views)

I must enter the elements to the vector just by pressing the button, I do not have much knowledge but I am trying to make it work, if you can help me thanks is very useful for me, my desire is to learn and if there is a better way please teach me

and to order the vector it can be in any way but it must have recursion, only in the VI of ordering the vector

0 Kudos
Message 5 of 14
(184 Views)
Solution
Accepted by topic author Nolbert

@Nolbert wrote:

I must enter the elements to the vector just by pressing the button, I do not have much knowledge but I am trying to make it work, if you can help me thanks is very useful for me, my desire is to learn and if there is a better way please teach me


You need to initialize the shift register with an empty array, then append with each click.

 

For the recursive bubble sort, the code can be 10x less complicated than what you have now. I just made one and it works well. Also make sure to measure the array size instead of using fixed diagram constants. The recursive sorting needs to ultimately work for arrays of any size.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 6 of 14
(181 Views)

maybe you can help me with an image of how I develop the recursive method

0 Kudos
Message 7 of 14
(173 Views)

I guess you got a solution. Here's what I just made up from scratch. Smiley Wink

 

BubbleSortRecursive.png

 

I won't attach any code and you still need to guess what's in the other case of the case structure. Smiley Wink


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 8 of 14
(172 Views)

Thank you

0 Kudos
Message 9 of 14
(166 Views)

15610604814389042110945168218331.jpg

this is fine to enter the data, or it is very extensive, and about the other case in the structure I still think, a question in the case of the photo is only to work on the first number? because I get a vector of zeros at the end does not take not the first value or is it the other case ??

0 Kudos
Message 10 of 14
(153 Views)