We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C solution
(not mine but I got it from below took too long me to scroll )
For a beginner like me who has just began data structures 2 weeks ago
this question left me scratching my mind for past 2 hours T-T
#include<stdio.h>#include<stdlib.h>voidquickSort(int*ar,intsize){if(size>1){inttemp,pivot=ar[0],ub=size-1;for(inti=size-1;i>=0;--i){if(ar[i]>=pivot){temp=ar[i];intj=i;while(j<ub){//Variation of Insertion Sortingar[j]=ar[j+1];++j;}ar[ub--]=temp;}}++ub;quickSort(ar,ub);quickSort(ar+ub+1,size-ub-1);//Outputfor(inti=0;i<size;++i){printf("%d ",ar[i]);}printf("\n");}}intmain(void){intN;scanf("%d",&N);intar[N];for(inti=0;i<N;i++){scanf("%d",&ar[i]);}quickSort(ar,N);return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 2 - Sorting
You are viewing a single comment's thread. Return to all comments →
C solution (not mine but I got it from below took too long me to scroll ) For a beginner like me who has just began data structures 2 weeks ago this question left me scratching my mind for past 2 hours T-T