How would you write qsort?



How would you write qsort?..

Answer / 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

More C Interview Questions

Can one function call another?

0 Answers  


Why does not c have an exponentiation operator?

0 Answers  


What is pointers in c?

0 Answers  


Which node is more powerful and can handle local information processing or graphics processing?

0 Answers  


study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above

15 Answers   Accenture, TCS,






What is the purpose of void pointer?

0 Answers  


What is wild pointer in c with example?

0 Answers  


Given an unsigned integer, find if the number is power of 2?

5 Answers  


A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.

2 Answers  


using only #include <stdio.h> and #include <stdlib.h> Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

0 Answers  


Write a c program to print the sizes and ranges of different data types in c?

1 Answers  


What are enums in c?

0 Answers  


Categories