When a person is told how a problem should be solved, and the results of a personal experiment OK, once encountered a similar problem, it will be conditioned directly to use this method. It is very rare to think about why this method, whether there is any hidden danger, there is no other way, and so on these problems.
At least that's what I am.
This semester, C language class, originally out of the topic let students put arbitrary strings in alphabetical order to output, is to let them practice the sorting algorithm.
One of the programs that a student handed in was this:
#include <stdio.h>#include<string.h>intMain () {Charch[ -],_mark;inti,n;scanf ("%s", ch); n=strlen (CH); _mark='A'; while(_mark<='Z'){ for(i=0; I {if(ch[i]==_mark) printf ("%c", Ch[i]); } _mark++;}return 0;}
It was clear that her idea was to traverse the string 26 times, starting with the smallest ' a ' to traverse through the same output, and then using ' B ' to traverse until the last capital letter ' Z '.
After I had probably mentioned the idea of sequencing, she thought about the output. Although the adaptability of this algorithm and the time complexity of the algorithm are very high, and from the point of view of the two evaluation procedures, the program is even slightly clumsy. But, it wins in easy to understand and ingenuity, really is let me pleasantly surprised!!
C language Teaching notes--alphabetical order