•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# Pseudocode - Please Clarify This Code For Me?

pseudocode

### #1 Splint3048

Splint3048

CC Lurker

• Just Joined
• 1 posts
• Learning:C

Posted 31 July 2012 - 03:05 AM

Hi,

I'm new to this site and new to programming. I've been thrown in the deep end to a certain extent in being asked to write some Pseudocode which, among other things finds a median value. I intend using a sort function as the first step to finding the median.

This is an Insertion Sort Pseudocode I grabbed off the web. Pseudocode is new to me and I'm not sure if I'm understanding it correctly. I put in the comments after >> signs. Can you please clarify what's going on and put in any relevant comments or corrections?

Suppose A is an array of N values. We want to sort A in ascending order.
Insertion Sort is an algorithm to do this as follows: We traverse the array and insert each element into the sorted part of the list where it belongs. This usually involves pushing down the larger elements in the sorted part.

For I = 1 to N-1 >> I = iterations of the selection process.
J = I >> J is a label for the number of the current iteration.
Do while (J > 0) and (A(J) < A(J - 1) >>J starts at 1 and stops at the second last iteration. Ref note below re last entry.
Temp = A(J) >>defining A(J) as the temp file where the N values will be stored in ascending order.
A(J) = A(J - 1) >>is this the sorting part?
A(J - 1) = Temp >>?
J = J - 1 >>?
End-Do
End-For

N-1 rather than N in the first line because the last value cannot be compared to another value as there are no other values left to compare to, so it is just put in the last cell of the temp matrix.

Thanks
David

P.S. sorry about the formatting, I cant get the lines to step in and appear as they should. Refer this http://faculty.cs.ni...241/sorting.htm link if it helps.
• 0

### #2 WingedPanther73

WingedPanther73

A spammer's worst nightmare

• Moderator
• 17757 posts
• Location:Upstate, South Carolina
• Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
• Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 31 July 2012 - 07:28 AM

What I would recommend: start with some data in front of you, and try tracing through what it does.
• 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

### Also tagged with one or more of these keywords: pseudocode

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download