Skip to content

Instantly share code, notes, and snippets.

@HSley13
Created September 5, 2023 11:14
Show Gist options
  • Save HSley13/066cf9ea114e4841237b077a3bfaf1af to your computer and use it in GitHub Desktop.
Save HSley13/066cf9ea114e4841237b077a3bfaf1af to your computer and use it in GitHub Desktop.
#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