Both of Numerical Analysis and Computational Geometry are important, and I want to let you know how to think about the Algorithm and Data Structure. When I meet a engineering problem, I always build a complex data structure with an easy algorithm to solve it. Why? If you carefully think about it, you shall discover that changing data structure is easier than changing algorithm. Of course, you have to build a flexible data structure, or you may be hard to change it.
My most familiar programming language is C, and I follow the ISO/IEC 9899:1999 standard which is the so-called C99. I always use the pointer to point the structure, so that I can easy to operate my data. Recently, I create a new sorting algorithm for the gutter sorting, and its performance is the fastest one among my 5 algorithms. I show you my source code, but the copyright belongs to my company, Songyang Engineering Consultants Co., Ltd. My gutter sorting algorithm is as follow:
I think my source code is very simple, and you can understand how to build my data structure directly. Hence, I won't show you the full source code about my data structure, and just show you the source code of my algorithm. When I built the algorithm, I tried to find the Natural Rules of the upstream and downstream gutters. Among my 5 algorithms, most of them are the stupid approaches. Why? I didn't find the natural rules, but I found it before I decided to choose the stupid approach.
Actually, I just need to distinguish the TOP and NON-TOP upstream gutters, and I can be easier to sort the gutters from upstream to downstream. This is the so-called natural rule, and it's just a little know-how. How do I discover the natural rule? I am just lucky. I think you have to learn how to discover the natural rules for a problem, or you may always use the stupid algorithms.
My most familiar programming language is C, and I follow the ISO/IEC 9899:1999 standard which is the so-called C99. I always use the pointer to point the structure, so that I can easy to operate my data. Recently, I create a new sorting algorithm for the gutter sorting, and its performance is the fastest one among my 5 algorithms. I show you my source code, but the copyright belongs to my company, Songyang Engineering Consultants Co., Ltd. My gutter sorting algorithm is as follow:
/*-------------------------------------------------------------------------- Sort Gutter from Upstream to Downstream ---*/
struct collection_int *Sort_Gutter() {
int index_i, index_j, index_remainder, index_remainder_id, index_sorted, index_sorted_id, _TEMP_INDEX;
struct collection_int *_remainder, *_sorted;
_remainder = (struct collection_int *) calloc(1, sizeof (struct collection_int));
_remainder->collection = (int *) calloc(_gutter->quantity, sizeof (int));
_sorted = (struct collection_int *) calloc(1, sizeof (struct collection_int));
_sorted->collection = (int *) calloc(_gutter->quantity, sizeof (int));
/*------------------------------------------------------------------ Distinguish TOP Upstream & Non-TOP Upstream ---*/
for (index_i = 0; index_i < _gutter->quantity; index_i++)
if (_gutter->collection[index_i].upstream_gutter_quantity == 0)
_sorted->collection[_sorted->quantity++] = _gutter->collection[index_i].ID;
else
_remainder->collection[_remainder->quantity++] = _gutter->collection[index_i].ID;
/*---------------------------------------------------------------------------------------- Sort Non-TOP Upstream ---*/
while (_remainder->quantity != 0)
for (index_remainder = 0, index_remainder_id = _remainder->collection[0]; index_remainder < _remainder->quantity;
index_remainder_id = _remainder->collection[++index_remainder]) {
for (index_i = 0; index_i < _gutter->quantity; index_i++)
if (_gutter->collection[index_i].ID == index_remainder_id) {
_TEMP_INDEX = index_i;
break;
}
for (index_i = 0; index_i < _gutter->collection[_TEMP_INDEX].upstream_gutter_quantity; index_i++)
for (index_sorted = 0, index_sorted_id = _sorted->collection[0]; index_sorted < _sorted->quantity;
index_sorted_id = _sorted->collection[++index_sorted])
if (_gutter->collection[_TEMP_INDEX].upstream_gutter[index_i]->ID == index_sorted_id) {
_sorted->collection[_sorted->quantity++] = _remainder->collection[index_remainder];
for (index_j = index_remainder + 1; index_j <= _remainder->quantity; index_j++)
_remainder->collection[index_j - 1] = _remainder->collection[index_j];
_remainder->collection[_remainder->quantity--] = 0;
break;
}
}
free(_remainder->collection);
free(_remainder);
return _sorted;
}
struct collection_int *Sort_Gutter() {
int index_i, index_j, index_remainder, index_remainder_id, index_sorted, index_sorted_id, _TEMP_INDEX;
struct collection_int *_remainder, *_sorted;
_remainder = (struct collection_int *) calloc(1, sizeof (struct collection_int));
_remainder->collection = (int *) calloc(_gutter->quantity, sizeof (int));
_sorted = (struct collection_int *) calloc(1, sizeof (struct collection_int));
_sorted->collection = (int *) calloc(_gutter->quantity, sizeof (int));
/*------------------------------------------------------------------ Distinguish TOP Upstream & Non-TOP Upstream ---*/
for (index_i = 0; index_i < _gutter->quantity; index_i++)
if (_gutter->collection[index_i].upstream_gutter_quantity == 0)
_sorted->collection[_sorted->quantity++] = _gutter->collection[index_i].ID;
else
_remainder->collection[_remainder->quantity++] = _gutter->collection[index_i].ID;
/*---------------------------------------------------------------------------------------- Sort Non-TOP Upstream ---*/
while (_remainder->quantity != 0)
for (index_remainder = 0, index_remainder_id = _remainder->collection[0]; index_remainder < _remainder->quantity;
index_remainder_id = _remainder->collection[++index_remainder]) {
for (index_i = 0; index_i < _gutter->quantity; index_i++)
if (_gutter->collection[index_i].ID == index_remainder_id) {
_TEMP_INDEX = index_i;
break;
}
for (index_i = 0; index_i < _gutter->collection[_TEMP_INDEX].upstream_gutter_quantity; index_i++)
for (index_sorted = 0, index_sorted_id = _sorted->collection[0]; index_sorted < _sorted->quantity;
index_sorted_id = _sorted->collection[++index_sorted])
if (_gutter->collection[_TEMP_INDEX].upstream_gutter[index_i]->ID == index_sorted_id) {
_sorted->collection[_sorted->quantity++] = _remainder->collection[index_remainder];
for (index_j = index_remainder + 1; index_j <= _remainder->quantity; index_j++)
_remainder->collection[index_j - 1] = _remainder->collection[index_j];
_remainder->collection[_remainder->quantity--] = 0;
break;
}
}
free(_remainder->collection);
free(_remainder);
return _sorted;
}
I think my source code is very simple, and you can understand how to build my data structure directly. Hence, I won't show you the full source code about my data structure, and just show you the source code of my algorithm. When I built the algorithm, I tried to find the Natural Rules of the upstream and downstream gutters. Among my 5 algorithms, most of them are the stupid approaches. Why? I didn't find the natural rules, but I found it before I decided to choose the stupid approach.
Actually, I just need to distinguish the TOP and NON-TOP upstream gutters, and I can be easier to sort the gutters from upstream to downstream. This is the so-called natural rule, and it's just a little know-how. How do I discover the natural rule? I am just lucky. I think you have to learn how to discover the natural rules for a problem, or you may always use the stupid algorithms.