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
(3,257 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?

0 Kudos
Message 2 of 14
(3,238 Views)

It's a Homework

0 Kudos
Message 3 of 14
(3,235 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?
0 Kudos
Message 4 of 14
(3,230 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
(3,226 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.

0 Kudos
Message 6 of 14
(3,223 Views)

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

0 Kudos
Message 7 of 14
(3,215 Views)

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

 

BubbleSortRecursive.png

 

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

0 Kudos
Message 8 of 14
(3,214 Views)

Thank you

0 Kudos
Message 9 of 14
(3,208 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
(3,195 Views)