Social Icons

banner image

quick sort in data structure

#include<iostream>
#include<conio.h>
using namespace std;
int l[10],u[10],a[10];
int top=-1,loc;
void quick(int beg, int end)
{
int l=beg, r=end;
int temp;
loc=l;
x:
while((loc!=r)&&(a[loc]<=a[r]))
{
r=r-1;
}
if(loc==r)
{
return;
}
if(a[loc]>=a[r])
{
temp=a[loc];
a[loc]=a[r];
a[r]=temp;
loc=r;
goto y;
}
y: while((loc!=l)&&(a[loc]>=a[l]))
{
l=l-1;
}
if(loc==l)
{
return;
}
if(a[loc]<=a[l])
{
temp=a[loc];
a[loc]=a[l];
a[l]=temp;
loc=l;
goto x;
}
}
int main()
{   int beg,end;
cout<<"enter the numbers\n";
for(int i=0;i<10;i++)
{
cin>>a[i];
}
cout<<"\nthe numbers you have entered";
for(int i=0;i<10;i++)
{
cout<<a[i]<<"  ";
}
top=top+1;
l[top]=0;
u[top]=9;
while(top!=-1)
{
beg=l[top];
end=u[top];
top--;
quick(beg,end);
if((loc-1)>beg)
{
top=top+1;
l[top]=beg;
u[top]=loc-1;
}
if((loc+1)<end)
{
top=top+1;
l[top]=loc+1;
u[top]=end;
}
}
}
quick sort in data structure quick sort in data structure Reviewed by Shobhit Goel on November 07, 2015 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.