954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert this quick sort

CONVERT THIS QUICK SORT PROGRAM INTO PARTITION OF 3,5,7OR 11 ELEMENTS.

#include"stdafx.h"
#include<iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#define size 50
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}

int partition(int i,int j )
{
return((i+j) /2);
}

void quicksort(int list[],int m,int n)
{
int key,i,j,k;
if( m < n)
{
k = partition(m,n);
swap(&list[m],&list[k]);
key = list[m];
i = m+1;
j = n;
while(i <= j)
{
while((i <= n) && (list[i] <= key))
i++;
while((j >= m) && (list[j] > key))
j--;
if( i < j)
swap(&list[i],&list[j]);
}

swap(&list[m],&list[j]);
quicksort(list,m,j-1);
quicksort(list,j+1,n);
}
}
void printlist(int list[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%d\t",list[i]);
}

void main()
{
int n,i;
int list[size];


printf("How many numbers do you want to enter");
scanf("%d",&n);
printf("Enter the numbers you want to sort");
for(i=0;i<n;i++)
{
scanf("%d",&list[i]);
}


printf("The list before sorting is:\n");
printlist(list,n);
quicksort(list,0,n-1);
printf("The list after sorting using quicksort algorithm:\n");
printlist(list,n);
system("pause");
}
mushahidh
Newbie Poster
6 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 
CONVERT THIS QUICK SORT PROGRAM INTO PARTITION OF 3,5,7OR 11 ELEMENTS.


So you've pinched some code from the web and now want us to make it do what you need to get a good grade? Hmm, no. Do your own damn homework.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

What you do is go up to your instructor and say "Excuse me, but I don't understand this assignment. While I understand quicksort, I don't understand what you mean when you say 'a partition of 3, 5, 7 or 11 elements'. Would you please help me to understand what it is you would like me to do?"

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: