0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
阅读程序下面,写出程序输出: (2007年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include "stdio.h" char ch[] = { 'q', 'A', 'S', 'O', 'R', 'T', 'E', 'X', 'A', 'M', 'P', 'L', 'E' }; int n = 12; void shift( int k, int n ){ char v; int j; v = ch[k]; j = k + k; while ( j <= n ){ if ( (j < n) && (ch[j] < ch[j + 1]) ) j++; if ( v < ch[j] ){ ch[j / 2] = ch[j]; j *= 2; }else return; ch[j / 2] = v; } } void hpsrt( void ){ int k; char tmp; for ( k = n / 2; k > 0; k-- ) shift( k, n ); /* 建堆*/ printf( "No.1: " ); for ( k = 1; k <= n; k++ ) putchar( ch[k] ); //putchar writes a character (an unsigned char) specified by the argument char to stdout. putchar( '\n' ); for ( k = n; k > 0; k-- ){ tmp = ch[1]; ch[1] = ch[k]; ch[k] = tmp; shift( 1, k - 1 ); } } int main(){ int k; hpsrt(); printf( "No.2: " ); for ( k = 1; k <= n; k++ ) putchar( ch[k] ); putchar( '\n' ); } |
No.1
No.2