# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## order a vector from highest to lowest using recursion

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

Message 1 of 14
(215 Views)

## Re: order a vector from highest to lowest using recursion

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
Message 2 of 14
(196 Views)

It's a Homework

Message 3 of 14
(193 Views)

## Re: order a vector from highest to lowest using recursion

• 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
Message 4 of 14
(188 Views)

## Re: order a vector from highest to lowest using recursion

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

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

## Re: order a vector from highest to lowest using recursion

@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
Message 6 of 14
(181 Views)

## Re: order a vector from highest to lowest using recursion

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

Message 7 of 14
(173 Views)

## Re: order a vector from highest to lowest using recursion

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

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

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

Thank you

Message 9 of 14
(166 Views)

## Re: order a vector from highest to lowest using recursion

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 ??

Message 10 of 14
(153 Views)