0% found this document useful (0 votes)
18 views

Exer CPP

This document describes a recursive version of Quicksort for sorting characters. The qs function takes in an array of characters, a left index, and a right index. It uses a partition approach, where it chooses a pivot element, partitions the array around that element, and recursively calls itself on the subarrays.

Uploaded by

alberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Exer CPP

This document describes a recursive version of Quicksort for sorting characters. The qs function takes in an array of characters, a left index, and a right index. It uses a partition approach, where it chooses a pivot element, partitions the array around that element, and recursively calls itself on the subarrays.

Uploaded by

alberto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

recursiv

e
version
of
Quicksor
t for
sorting
characte
rs.
void
qs(char
*items,
int left,
int right)
{
int i, j;
char x,
y;
i = left;
j = right;
**********
**********
*
**
'jumpstm
t.cpp'
Progra
m
repeated
ly
accepts
as input
a
*
characte
r and
tests it
for being
a
number
*
in the
range 1-
7 for a
day of
the
week.
**********
**********
**********
**********
**********
**********
**********
*/
#include
<iostrea
m>
using
namesp
ace std;
#include
<cstdio>
int
main()
{
int c;
cout <<
"Enter a
single-
digit
number:
";
while ((c
=
getchar()
) !=EOF)
{
if ((c ==
'\n') || (c
== '\r'))
continue
;
if ((c <
'0') || (c
> '9'))
{
cout <<
"You
must
enter a
single-
digit
number"
<< endl;
cout <<
"Enter a
number:
";
continue
;
}
switch(c)
{
case '8':
case '9':
cout <<
"Number
not in
range 1-
7 "<<
endl;
break;
if(i <= j) {

y = items[i];

items[i] = items[j];

items[j] = y;

i++; j--;

} while(i <= j);

if(left < j) qs(items, left, j);

if(i < right) qs(items, i, right);

} cout << " // ...\n";

cout << "}\n";

break;

case '3':

cout << "The for:\n\n";

cout << "for(init; condition; iteration)";

cout << " statement;\n";

break;

case '4':

cout << "The while:\n\n";

cout << "while(condition) statement;\n";

break;

case '5':

cout << "The do-while:\n\n";

cout << "do {\n";

cout << " statement;\n";

cout << "} while (condition);\n";

break;

case '6':
cout << "The break:\n\n";

cout << "break;\n";

break;

case '7':

cout << "The continue:\n\n";

cout << "continue;\n";

break;

case '8':

cout << "The goto:\n\n";

cout << "goto label;\n";

break;

cout << "\n";

return 0;

You might also like