what's wrong with my program?

  • Thread starter Thread starter Jason Felix
  • Start date Start date
J

Jason Felix

#include<iostream>
#include<cstring>
using namespace std;

void quicksort(char *num,int len);
void qs(char *num,int left,int right);

int main()
{
char num[]="3,7,3,6,7,9,5,4,1,7,8,90,5,334,54,213,78";

cout<<"Original: "<<num<<"\n";

cout<<"sorting......"<<"\n";

quicksort(num,numlen(num));

cout<<"sorted: "<<num<<"\n";

return 0;
}

void quicksort(char *num,int len)
{
qs(num,0,len-1);
}

void qs(char *num,int left,int right)
{
int i,j;
char x,y;

i=left;j=right;
x=num[(left+right)/2];

do{
while((num<x)&&(i<right))i++;

while((y>num[j])&&(j>left))j--;

if(i<=j){
y=num;
num=num[j];
num[j]=y;
i++;j--;
}
}while(i<=j);
}
 
Hi Jason!
char num[]="3,7,3,6,7,9,5,4,1,7,8,90,5,334,54,213,78";

What are you trying to do?
Do you want to sort characters or numbers?

if you want to sort number you should decalre it as:
int num[] = {3,7,3,6,7,9,5,4,1,7,8,90,5,334,54,213,78};
quicksort(num,numlen(num));

What is "numlen" ?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
Back
Top