The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

recursive -> iterative by dennismv2004-12-21 02:24:43
  I don't have time to give a full answer... by Liava2004-12-21 03:55:22
    Qsort by dennismv 2004-12-21 04:15:00
I have both versions of QSort -- recursive and iterative.
I didn't have to make any significant changes to the recursive version, except adding a stack.

Thus, both versions are equivalent in their functionality. i.e. they do the same thing.

Also, I've noted that there are certain differences between recursive and iterative versions.
For example, qsort sorts on on an array on indices from i to j, where i<j.

If you happened to generate i and j such that i>=j (no need to sort), recursive version had to actually enter a function to see this, and return right away.
With iterative version you first generate i and j, and then push them on the stack. If you generate i>=j, you have an option to not push them on the stack, thus "saving" a would-be recursive call. In other words, in iterative version you can "move" certain things out of the recursive function, outside the recursive function, if this makes sense.
[ Reply ]
      I'd still call that a recursive solution, though by Liava2004-12-21 04:30:46
        recursion by dennismv2004-12-21 04:50:19
          I have gotten rid of the recursive call by Version0.12004-12-21 08:40:48
          Well, the algorithm is as follows: by Liava2004-12-21 11:46:07
            ok by dennismv2004-12-21 19:34:10
              Not what I meant by Liava2004-12-21 22:05:31
                Much of this could be avoided. by williamashbless2004-12-21 23:32:22

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)