15#include "fasp_functs.h"
21static void dSwapping (
REAL *w,
const INT i,
const INT j);
22static void iSwapping (
INT *w,
const INT i,
const INT j);
53 if (value < list[m]) {
56 else if (value > list[m]) {
87 if ( size == 0 )
return(0);
89 for ( newsize = 0, i = 1; i < size; ++i ) {
90 if ( numbers[newsize] < numbers[i] ) {
92 numbers[newsize] = numbers[i];
121 INT i, left_end, num_elements, tmp_pos;
125 num_elements = right - left + 1;
127 while ((left <= left_end) && (mid <= right)) {
129 if (numbers[left] <= numbers[mid])
131 work[tmp_pos] = numbers[left];
132 tmp_pos = tmp_pos + 1;
137 work[tmp_pos] = numbers[mid];
138 tmp_pos = tmp_pos + 1;
143 while (left <= left_end) {
144 work[tmp_pos] = numbers[left];
146 tmp_pos = tmp_pos + 1;
149 while (mid <= right) {
150 work[tmp_pos] = numbers[mid];
152 tmp_pos = tmp_pos + 1;
155 for (i = 0; i < num_elements; ++i) {
156 numbers[right] = work[right];
185 mid = (right + left) / 2;
214 if (left >= right)
return;
216 iSwapping(a, left, (left+right)/2);
219 for (i = left+1; i <= right; ++i) {
220 if (a[i] < a[left]) {
221 iSwapping(a, ++last, i);
225 iSwapping(a, left, last);
252 if (left >= right)
return;
254 dSwapping(a, left, (left+right)/2);
257 for (i = left+1; i <= right; ++i) {
258 if (a[i] < a[left]) {
259 dSwapping(a, ++last, i);
263 dSwapping(a, left, last);
293 if (left >= right)
return;
295 iSwapping(index, left, (left+right)/2);
298 for (i = left+1; i <= right; ++i) {
299 if (a[index[i]] < a[index[left]]) {
300 iSwapping(index, ++last, i);
304 iSwapping(index, left, last);
334 if (left >= right)
return;
336 iSwapping(index, left, (left+right)/2);
339 for (i = left+1; i <= right; ++i) {
340 if (a[index[i]] < a[index[left]]) {
341 iSwapping(index, ++last, i);
345 iSwapping(index, left, last);
367static void iSwapping (
INT *w,
371 const INT temp = w[i];
372 w[i] = w[j]; w[j] = temp;
387static void dSwapping (
REAL *w,
391 const REAL temp = w[i];
392 w[i] = w[j]; w[j] = temp;
INT fasp_aux_BiSearch(const INT nlist, const INT *list, const INT value)
Binary Search.
void fasp_aux_iQuickSortIndex(INT *a, INT left, INT right, INT *index)
Reorder the index of (INT type) so that 'a' is in ascending order.
void fasp_aux_merge(INT numbers[], INT work[], INT left, INT mid, INT right)
Merge two sorted arrays.
void fasp_aux_msort(INT numbers[], INT work[], INT left, INT right)
Sort the INT array in ascending order with the merge sort algorithm.
void fasp_aux_dQuickSortIndex(REAL *a, INT left, INT right, INT *index)
Reorder the index of (REAL type) so that 'a' is ascending in such order.
void fasp_aux_dQuickSort(REAL *a, INT left, INT right)
Sort the array (REAL type) in ascending order with the quick sorting algorithm.
void fasp_aux_iQuickSort(INT *a, INT left, INT right)
Sort the array (INT type) in ascending order with the quick sorting algorithm.
INT fasp_aux_unique(INT numbers[], const INT size)
Remove duplicates in an sorted (ascending order) array.
Main header file for the FASP project.