Start New Discussion within our Software Development Community

dont know what is wrong with this, wont give me the result. please help

#include <iostream.h>
#include<stdlib.h>
#include <process.h>
#include <conio.h>
class SortList
{
private :
int *list;
int size;
public :
SortList(int size)
{
list=new int[size];
this->size=size;
}
void Swap(int i,int j)
{
int tmp;
tmp=list[i];
list[i]=list[j];
list[j]=tmp;
}
void SortList::QuickSort(int,int);
void StoreNum(int);
void Display();
};
void SortList::StoreNum(int x)
{
static int i=0;
*(list+i)=x;
i++;
}
void SortList::Display()
{
int i=0;
for(;i<size;i++)
cout<<*(list+i)<<" ";
}
void SortList::QuickSort(int X,int I)
{
int L,R,V;
if (I>X)
{
V=list[I];
L=X-1;
R=I;
for(;;)
{
while(list[++L]>V);
while(list[--R]<V);
if (L==R) break;
Swap(L,R);
}
Swap(L,I);
QuickSort(X,L-1);
QuickSort(L+1,I);
}
}

void main()
{
int i,x,n;
SortList *S;
system("cls");
cout<<endl<<"\t"<<"Program for Quick Sort"<<endl;
cout<<endl<<"How many numbers to be sorted : ";
cin>>n;
S=new SortList(n);
for(i=0;i<n;i++)
{
cout<<endl<<"Enter number : ";
cin>>x;
S->StoreNum(x);
}
cout<<endl<<"Numbers entered are "<<endl;
S->Display();
S->QuickSort(1,n-1);
cout<<endl<<"Numbers After QuickSort are "<<endl;
S->Display();
}

Indent your code properly.
Just telling the program won't give you the result doesn't help. Tell us what you expect and what the program gives actually.

void SortList::QuickSort(int X,int I)
{
int L,R,V;
if (I>X)
{
V=list[[B]i[/B]];[B]// what is this simple i? I don't see it declared anywhere.[/B]
L=X-1;
R=I;
for(;;)
{
while(list[++L]>V);
while(list[--R]<V);
if (L==R) break;
Swap(L,R);

}

repost your properly indented code with the above correction and a better explaination of the problem.

This article has been dead for over six months. Start a new discussion instead.