Current location - Education and Training Encyclopedia - Educational institution - Central education
Central education
Quick sort: where t is the number of tests and n is the number of elements.

# Including

& ltiostream & gt

use

Namespace

std

Internationalorganizations (same as international organizations)

Partition (int

*s,

Internationalorganizations (same as international organizations)

Low,

Internationalorganizations (same as international organizations)

High)

{

Internationalorganizations (same as international organizations)

I

j,

t;

Internationalorganizations (same as international organizations)

pivot

=

S[ low];

j

=

Low;

for

(I

=

low

+

1;

I

& lt=

High;

i++)

{

if

(s[i]

& lt

Pivot)

{

j++;

t

=

s[I];

s[i]

=

s[j];

s[j]

=

t;

}

}

t

=

s[j];

//Swap pivot and the last number of the sequence less than pivot.

s[j]

=

Pivot;

S[ low]

=

t;

return

j;

}

empty

Quick sort (integer

*s,

Internationalorganizations (same as international organizations)

Low,

Internationalorganizations (same as international organizations)

High)

{

Internationalorganizations (same as international organizations)

Pivot;

//Central perspective

if

(low

& lt

High)

{

pivot

=

Partition,

Low,

High);

Quick sort,

Low,

pivot

-

1);

//Recursively sort the low-order sub-table.

Quick sort,

pivot

+

1,

High);

//Recursively sort the high child tables.

}

}

Internationalorganizations (same as international organizations)

Master ()

{

Internationalorganizations (same as international organizations)

t,

n;

Internationalorganizations (same as international organizations)

Me;

Internationalorganizations (same as international organizations)

a[ 1000];

cin

& gt& gt

t;

During ...

(T -)

{

cin

& gt& gt

n;

for

(I

=

0;

I

& lt

n;

i++)

cin

& gt& gt

a[I];

Quick sort (a,

0,

ordinary

-

1);

for

(I

=

0;

I

& lt

n;

i++)

Standard output

& lt& lt

a[i]

& lt& lt

endl

}

return

0;

}

Bubble sorting algorithm: where t is the number of tests and n is the number of elements.

# Including

& ltiostream & gt

use

Namespace

std

Internationalorganizations (same as international organizations)

Master ()

{

Internationalorganizations (same as international organizations)

t,

n;

Internationalorganizations (same as international organizations)

I

j,

k,

t;

Internationalorganizations (same as international organizations)

a[ 1000];

cin

& gt& gt

t;

During ...

(T -)

{

cin

& gt& gt

n;

for

(I

=

0;

I

& lt

n;

i++)

cin

& gt& gt

a[I];

for

(j

=

0;

j

& lt

ordinary

-

1;

j++)

{

for

(k

=

0;

k

& lt

ordinary

-

j

-

1;

k++)

{

if

(a[k]

& gt

a[k]

+

1])

{

t

=

a[k]

+

1];

a[k]

+

1]

=

a[k];

a[k]

=

t;

}

}

}

for

(I

=

0;

I

& lt

n;

i++)

Standard output

& lt& lt

a[i]

& lt& lt

endl

}

return

0;

}