help with c++(sorting)

Discussion in 'The Projects Forum' started by chaithanyatkm, Oct 14, 2011.

  1. chaithanyatkm

    Thread Starter New Member

    Aug 26, 2011
    23
    0
    could anyone please transform this algorithm for quick sort to a program
    Algorithm
    x is the array,first indicates index of first element& last indicates index of last element.
    sort(first,last)
    start
    if(first<last)
    {
    pivot=x[first]
    i=first
    j=last
    while(i<j)
    {
    while(x<=pivot and i<last)
    i=i+1
    while(x[j]>=pivot and j>first)
    j=j-1
    if(i<j)
    {temp=x
    x=x[j]
    x[j]=temp
    }
    }//end of while
    temp=x[first]
    x[first]=x[j]
    x[j]=temp
    call sort(first,j-1)
    call sort(j+1,last)
    }//end of if
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Code ( (Unknown Language)):
    1. sort(first,last)
    2. start
    3. if(first<last)
    4. {
    5.   pivot=x[first]
    6.   i=first
    7.   j=last
    8.   while(i<j)
    9.    {
    10.     while(x[i]<=pivot and i<last)
    11.     i=i+1
    12.     while(x[j]>=pivot and j>first)
    13.     j=j-1
    14.     if(i<j)
    15.      {temp=x[i]
    16.       x[i]=x[j]
    17.       x[j]=temp
    18.      }
    19.    }//end of while
    20.    temp=x[first]
    21.    x[first]=x[j]
    22.    x[j]=temp
    23.  call sort(first,j-1)
    24.  call sort(j+1,last)
    25. }//end of if[/i][/i][/i]
    Please use the CODE tag to make it legible.
     
  3. chaithanyatkm

    Thread Starter New Member

    Aug 26, 2011
    23
    0
    what is this CODE tag.. i don't know
     
  4. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    When you type your reply, between the buttons there is one that looks like #. That wraps [ code] [ /code] around the text.

    As for the code, do you know anything from c++? If you don't, try reading some tutorial on C and it should be pretty straightforward what needs to be changed.
     
  5. ajm113

    Member

    Feb 19, 2011
    176
    5
    Best website ever created after google of course:
    http://www.cplusplus.com/

    Will give you great examples to everything such as strings, vectors, and etc.

    Please post programming questions here:
    Programmer's Corner

    This forum section is for showing off WIP Projects though you can ask for help here on projects, but for small scripts that do little tasks made with C++, Java and what not go on Programmers corner.
     
    Last edited: Oct 14, 2011
  6. #12

    Expert

    Nov 30, 2010
    16,346
    6,833
    Watch out about that, "best website ever". The best website ever is allaboutcircuits!
     
  7. ajm113

    Member

    Feb 19, 2011
    176
    5
    Woops, excuse me, let me say that again. It's the best website for C++ references when you want example code with almost all the standard headers. Such as Strings, Vectors, math functions, array functions and more. :)
     
Loading...