Fortran 90 Implicit None and Vector Sorting Methods

Classified in Mathematics

Written at on English with a size of 1.74 KB.

Fortran 90: Implicit None and Vector Management

Implicit None

In Fortran 90, undeclared variables starting with I, J, K, L, or M are treated as integers, while others are treated as real numbers. However, it's best practice to avoid implicit declarations. Use IMPLICIT NONE right after the program instructions to disable implicit typing. This forces you to explicitly declare all variables, preventing potential errors due to character misuse.

Vector Management Forms

Ordering one-dimensional arrays (vectors) is a common operation. Here are three simple methods: selection, insertion, and bubble sort.

In all cases, we'll assume a one-dimensional array of N elements.

Selection Sort

  1. Find the smallest element in the vector.
  2. Swap it with the element in the first position.
  3. Repeat the process for the rest of the vector (excluding the already sorted first element).
  4. Continue until only one element remains. This last element will be in the final position and will be the largest.

Insertion Sort

  1. Assume the first I-1 elements of a vector of N elements are sorted.
  2. Take the Ith element and insert it into its correct sorted position among the first I elements. Shift elements larger than the Ith element to the right to make space.
  3. Repeat the process, incrementing I.
  4. Start with I=2 and end when I=N.

Bubble Sort

  1. Compare each element with its neighbor to the right. If they are in the wrong order, swap them. Repeat this from the first to the second-to-last element.
  2. After step 1, the largest element will be at the end of the vector.
  3. Repeat the process, excluding the last (sorted) element.

Entradas relacionadas: