criminal pseudo code.

7 views
Skip to first unread message

Søren Kyale

unread,
May 3, 2013, 9:03:08 PM5/3/13
to uic-mcs...@googlegroups.com
It's one thing to be vague, it's a lot worse to be specific when nothing is specified.

Swap makes sense when you're talking about two things. When you're talking about thee things, there are five ways to swap them not counting leaving them as they are.

Rotate is more helpful, yet there are two directions that something can be rotated in.

Yet it takes memory to swap things so it's really crazy to do repeat rotations. It's more sensible to put something in one place and move one or two things at a time. And then move the outstanding item after everything is else is in place.

With insertion sort, a 'hole' my be used while other elements are moved one at a time to make room for insertion.

I may post some improved pseudo code to help with project 5.

In the meantime. I hope it you can look at 'swap' as clockwise rotation.
So clockwiseRotationWithIndexFunctionsMislablededAs'swap'(a,b,c)
means:
move list items from positions a->b->c->a

or in python, where L is list and a,b,c are indices. 
(L[b],L[c],L[a]) = (L[a],L[b],L[c])

the ++ means increment first.
so CRWIFMA'swap'(a,b++,c)
is the same as
b = b+1
followed by
(L[b],L[c],L[a]) = (L[a],L[b],L[c])

Keep in mind that the whole point of pseudo code is to be understood by humans.

Søren Kyale

unread,
May 4, 2013, 12:42:09 AM5/4/13
to uic-mcs...@googlegroups.com
I realized that I misread the swap function. It really is a swap. It's just that in some places the list is implied.
As in simple bubble sort with:
"swap(i, i+1).

And in other places (for added confusion) the list is given explicitly.
As in simple quick sort with:
swap (x, low, m), where x is the list.

The codes still makes no sense (has twice as many swap operations as necessary).

So I apologize for any misleading.

So the the argument swap(x, a, b) is the same as python:
x[a], x[b] = x[b], x[a]

Hope this clears up some confusion.
Reply all
Reply to author
Forward
0 new messages