Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Quick sort

$
0
0

Please help me out. I am not able to get output for my quick sort programe. Code is given below

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

void merge(int arr[],int minm,int mid,int maxm)
{int i,j,l;
 int t[maxm];
 for(i=0,j=mid,l=0;i<mid||j<maxm;)
 {
     if(arr[i]<=arr[j])
        {t[l]=arr[i];
         l++;
         i++;}
     else
       {t[l]=arr[j];
        l++;
        j++;}
 }
if(i==mid)
    for(;j<maxm;)
{
    t[l]=arr[j];
    l++;
    j++;
}

if(j==maxm)
    for(;i<maxm;)
{
    t[l]=arr[i];
    l++;
    i++;
}

 for(i=0;i<maxm;i++)
    arr[i]=t[i];
}

void mergesort(int a[],int p,int n)
{int mid;
 if(p<n)
 {mid=(p+n)/2;
 mergesort(a,p,mid);
 mergesort(a,mid,n);
 merge(a,p,mid,n);}

}

int main()
{int n,j;
printf("Enter the value of n");
scanf("%d",&n);
int a[n];
for(j=0;j<n;j++)
{ printf("Enter the value of n %d",j);
  scanf("%d",&a[j]);
}

mergesort(a,0,n);


for(j=0;j<n;j++)
{ printf("The value of n %d is %d",j,a[j]);

}
return 1;

}

Viewing all articles
Browse latest Browse all 39796

Trending Articles