Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi there, I'm having trouble completing the following code in C, any help would be appreciated and so would a sample output. The following uses

Hi there, I'm having trouble completing the following code in C, any help would be appreciated and so would a sample output. The following uses quicksort Thank you!

#include

void quicksort(int [10],int,int);

int main(){

int x[20],size,i;

printf("Enter size of the array: ");

scanf("%d",&size);

printf("Enter %d elements: ",size);

for(i=0;i

scanf("%d",&x[i]);

printf(" ");

for(i=0; i

printf(" %4d", x[i]);

printf(" ");

quicksort(x,0,size-1);

printf(" Sorted elements: ");

for(i=0;i

printf(" %4d",x[i]);

printf(" ");

return 0;

}

void quicksort(int x[10],int first,int last){

int pivot,j,temp,i;

if(first

pivot=first;

i=first;

j=last;

while(i

while(x[i]<=x[pivot]&&i

i++;

while(x[j]>x[pivot])

j--;

if(i

temp=x[i];

x[i]=x[j];

x[j]=temp;

}

}

temp=x[pivot];

x[pivot]=x[j];

x[j]=temp;

quicksort(x,first,j-1);

quicksort(x,j+1,last);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

Tell what the word schizophrenia means.

Answered: 1 week ago