JavaScript
  Home arrow JavaScript arrow Page 2 - 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 - Swapping Elements


    (Page 2 of 6 )

    When the index variables cross, they will be identifying elements, that is, the ith variable will be identifying the next element that is greater that the left element, or it will be identifying the last element if no element was found greater than the left element. Meanwhile, the jth variable will be identifying the next element that is less than the left element or it will be identifying the first (left) element if no element was less than the left element. The situation when our variables cross, is as follows:


    P

    W

    E

    I

    T

    Y

    U

    R

    O

    Q




    j

    i







    I

    O

    E

    P

    T

    Y

    U

    R

    W

    Q




    j

    i







    Look at the first of the two tables above carefully. Note that if we swap the present pair and continue to increment i, decrement j, and swap, we shall be reversing our process. We have to stop here.

    Actually we can use either the left or the right element as the pivot. Well, we shall use the left element as I said above. It can be shown that the position for the index variable, j, at the moment, is the final (sorted) position for the left element, P. So we swap the left element and the element at position j. Doing this with our array gives us the pivot, P, at its final position. The situation is as follows:


    [I O E] (P3) [T Y U R W Q] --------result 1


    We have the pivot at position 3, the left sub-list and the right sub-list. The index variable k that we mention above takes its first value of 3. We have to repeat the same process for the left sub-list and right sub-list. Let us start with the left sub-list.

    More JavaScript Articles
    More By Chrysanthus Forcha


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

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - 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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek