I need help arranging a vector using recursion please.
이전 댓글 표시
I am working on a function called vecSort that is supposed to arrange a vector from the smallest element to the largest using recursion. I cannot use the 'sort' function or any function similar to it. I have to use the min and/or max functions. This is what I have so far:
function vectorSort(vec)
L=length(vec);
if L<1
vec=[];
elseif L==1
vec=vec;
else i>1;
I have set the terminating condition but I cannot figure out how to get function to call on itself to arrange the vector from the minimum element to the largest element.
댓글 수: 3
Walter Roberson
2017년 11월 5일
Is it intended that there be a second routine to combine two already-sorted vectors?
Note: remember that recursive routines need to return a value.
Walter Roberson
2017년 11월 5일
You cannot sort recursively in any useful way unless you also have a phase for combining already-sorted regions.
Kevin Smith
2017년 11월 6일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!