Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How would you write qsort?

Answer Posted / hardik

#include<stdio.h>
#include<conio.h>
void sort(int,int);
int *arr;

void main()
{
clrscr();
int n,ub,lb=0,i;
printf("ENTER NO OF VALUES U WANT TO ENTER : ");
scanf("%d",&ub);
for(i=0;i<ub;i++)
{
printf("\ENter value : ");
scanf("%d",&arr[i]);
}
sort(lb,ub);
for(i=0;i<ub;i++)
printf("%d\t",arr[i]);
getch();
}
void sort(int lb,int ub)
{
int flag=1,temp,key,i,j;
i=lb; j=ub;
key=arr[i];
if(lb<ub)
{
while(flag)
{
i++;
while(key>arr[i])
i++;
while(key<arr[j])
j--;
if(i<j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
else
flag=0;
}
temp=arr[lb];
arr[lb]=arr[j];
arr[j]=temp;
sort(lb,j-1);
sort(j+1,ub);
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we need arrays in c?

1161


Can you write the function prototype, definition and mention the other requirements.

1146


How to write a code for reverse of string without using string functions?

2154


What is a list in c?

1035


What will be the outcome of the following conditional statement if the value of variable s is 10?

1301


Explain how do you declare an array that will hold more than 64kb of data?

1460


What is the use of sizeof () in c?

1060


What is sizeof in c?

1014


What is substring in c?

1210


What are the different types of linkage exist in c?

1035


Explain pointer. What are function pointers in C?

1087


How do I send escape sequences to control a terminal or other device?

1082


Is there a way to jump out of a function or functions?

1108


What's the total generic pointer type?

1061


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

1258