Tuesday, May 3, 2011

Sequencing maximum / minimum in C++

Called sequencing maximum / minimum because it is based on the selection of the maximum or minimum element then exchange element maximum / minimum by the end of array elements (elements of the left end or right end of elements). Furthermore, the tip element that we are "isolated" and not be included in the next process. Because the primary process is the selection of elements in the sorting maximum / minimum, this method is called the method of selection (selection sort).
 
Let us check sample program:

 
# include <iostream>
# include <conio.h>
# include <iomanip.h>

int main () {
/ / declare an array with 7 elements
int A [7];
int j, k, i, temp;
int jmax, u = 6;

/ / insert value before the sorted
court <<"Enter a value in array element:" <<endl;
for (i = 0; i <7; i + +)
{
  court <<"A [" <<i <<"]=";
  cin>> A [i];
}

/ / The process of sorting in ascending (Ascending)
for (j = 0, j <7; j + +)
{
  jmax = 0;
  for (k = 1; k <= u; k + +)
  if (A [k]> A [jmax])
      jmax = k;

  temp = A [u];
  A [u] = D [jmax];
  D [jmax] = temp;
  u -;
}
/ / display the value after sorted
court <<"\ nNilai after sorted =" <<endl;
for (i = 0; i <7; i + +)
  court <<A [i] <<"";
getch ();}

No comments:

Post a Comment