# help with c++(sorting)

#### 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,736
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.

#### chaithanyatkm

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

#### kubeek

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

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:

#### #12

Joined Nov 30, 2010
18,216
Watch out about that, "best website ever". The best website ever is allaboutcircuits!

#### 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.