JavaScript
  Home arrow JavaScript arrow Page 4 - QuickSort in Action
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

QuickSort in Action
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-10-27

    Table of Contents:
  • QuickSort in Action
  • Swapping Elements
  • Tackling a Sub-list
  • And Then There was One
  • Code for Quicksort
  • Sorting Strings

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    QuickSort in Action - And Then There was One


    (Page 4 of 6 )

    The algorithm (implementation) has to continue. The left element now is O; the right element is still O. The left element is compared with the right element; and since they are the same, no swapping takes place. Since there is only one element, i should not be incremented and j should not also be decrementing. This results in the following:


    O

    j, i


    We now exchange the left element, O, with the element of the position for j, which is still O. So O is exchanged with itself. The new value for the index variable k is now 2, the final position for O in the main list. The sub-list can now be written as:


    (O2)


    Now, note that there is no sub-list at all; no left and no right sub-list. My computer implementation is such that the computer will always move to sort the sub-list on the left of the found pivot. If there is no sub-list on the left, it goes to sort the immediate right sub-list. But if there is no immediate right sub-list, which is our current situation, it sorts the right sub-list that it did not sort before the present level of sorting. So it has to sort the following sub-list:

    [T Y U R W Q]

    This happens to be the first right sub-list we had. The algorithm (implementation) is repeated for this sub-list: the left and right elements are compared and exchanged if necessary. The pivot is obtained. Two sub-lists are developed; the left sub-list is sorted first.

    Note that the series of steps keep repeating themselves. In the process of sorting, the left sub-list is sorted first before the right sub-list. This process continues until the sorting is complete.

    Note that the algorithm (implementation) keeps calling itself (repeating) as you go down the sorting process. This is called recursion. That is, the sorting function has to keep calling itself.

    More JavaScript Articles
    More By Chrysanthus Forcha


       · Thanks for stopping by to read my article. If you have any comments, questions, or...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT