Created
September 5, 2023 11:14
-
-
Save HSley13/066cf9ea114e4841237b077a3bfaf1af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdio> | |
#include <cctype> | |
#include <cstdlib> | |
#include <cmath> | |
using namespace std; | |
void qs(char *item, int left, int right) | |
{ | |
int i, j; | |
char x, y; | |
i=left; j=right; | |
x= item[(left + right)/2]; | |
while(i<=j) | |
{ | |
while ((item[i]<x) && (i<right)) i++; | |
while ((item[j]>x) && (left<j)) j--; | |
if (i<=j) | |
{ | |
y= item[i]; | |
item[i]= item[j]; | |
item[j]= y; | |
i++; | |
j--; | |
} | |
if (left<j) qs(item, left, j); | |
else if (i<right) qs(item, right, i); | |
} | |
} | |
void quicksort(char *item, int len) | |
{ | |
qs (item, 0, len-1); | |
} | |
int main() | |
{ | |
char l[]= "gefdbca"; | |
int a; | |
cout<<" The Original sentence is :"<<l<<endl; | |
a= strlen(l); | |
quicksort(l,a); | |
cout<<" The corrected sentence is :"<<l<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment