Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
sorting algorithms

Subject: sorting algorithms

From: Buddy Britton

Date: 3 May, 2011 22:50:23

Message: 1 of 5

Trying to write a function to sort without using the sort function. Any help?


EX:
array1=[4,2,6,1,3] %orig array before sort
array2=[2,4,7,1,5] %the "paired" array

newarray1=[1,2,3,4,6] %orig array just sorted
newarray2=[1,4,5,2,7] %second array sorted according to the first array

Subject: sorting algorithms

From: TideMan

Date: 3 May, 2011 23:41:33

Message: 2 of 5

On May 4, 10:50 am, "Buddy Britton" <buddy_brit...@hotmail.com> wrote:
> Trying to write a function to sort without using the sort function. Any help?
>
> EX:
> array1=[4,2,6,1,3] %orig array before sort
> array2=[2,4,7,1,5] %the "paired" array
>
> newarray1=[1,2,3,4,6] %orig array just sorted
> newarray2=[1,4,5,2,7] %second array sorted according to the first array

This seems like a pointless exercise to me.
Why not use the tried and true, in-built Matlab function sort?

Subject: sorting algorithms

From: John D'Errico

Date: 3 May, 2011 23:47:05

Message: 3 of 5

"Buddy Britton" wrote in message <ipq0rf$6fq$1@fred.mathworks.com>...
> Trying to write a function to sort without using the sort function. Any help?
>
>
> EX:
> array1=[4,2,6,1,3] %orig array before sort
> array2=[2,4,7,1,5] %the "paired" array
>
> newarray1=[1,2,3,4,6] %orig array just sorted
> newarray2=[1,4,5,2,7] %second array sorted according to the first array

Sure. Just call the function min, repeatedly, deleting each
element as you find it.

Did you say the algorithm had to be efficient? These
homework assignments are so picky.

John

Subject: sorting algorithms

From: Roger Stafford

Date: 4 May, 2011 00:00:22

Message: 4 of 5

"Buddy Britton" wrote in message <ipq0rf$6fq$1@fred.mathworks.com>...
> Trying to write a function to sort without using the sort function. Any help?
> .......

Take a look at:

 http://en.wikipedia.org/wiki/Sorting_algorithm

to get started.

Roger Stafford

Subject: sorting algorithms

From: Steven_Lord

Date: 4 May, 2011 13:58:39

Message: 5 of 5



"Buddy Britton" <buddy_britton@hotmail.com> wrote in message
news:ipq0rf$6fq$1@fred.mathworks.com...
> Trying to write a function to sort without using the sort function. Any
> help?
>
>
> EX:
> array1=[4,2,6,1,3] %orig array before sort
> array2=[2,4,7,1,5] %the "paired" array
>
> newarray1=[1,2,3,4,6] %orig array just sorted
> newarray2=[1,4,5,2,7] %second array sorted according to the first array

\begin{tongueInCheek}
Knuth, The Art of Computer Programming, volume 3.
\end{tongueInCheek}

\begin{serious}
This sounds like a homework question and in general this newsgroup requires
people posting homework questions (or questions that sound like they're
homework, even if they're not) to show what they've done to try to solve the
problem and to ask a SPECIFIC question before the readers will offer any
suggestions. Post the code you've written to try to solve those questions
and indicate where EXACTLY you're stuck and someone may offer some
assistance.
\end{serious}

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us