help with c++(sorting)

Thread Starter

chaithanyatkm

Joined Aug 26, 2011
23
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
 

kubeek

Joined Sep 20, 2005
5,731
Rich (BB code):
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
Please use the CODE tag to make it legible.
 

kubeek

Joined Sep 20, 2005
5,731
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.
 

ajm113

Joined Feb 19, 2011
174
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:

ajm113

Joined Feb 19, 2011
174
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. :)
 
Top