|
![]() | 作者: lovejiang [lovejiang]
![]() |
登录 |
#include <stdio.h> main() { int a[10],i,n,j; a[0]=4; a[1]=3; for(i=2;i<10;i++) {printf("a[%d]=",i); scanf("%d",&a[i]); j=i-1; n=a[i]; while(n>a[j]){ a[i]=a[j]; if(j=0)a[0]=n; else j--;} a[j+1]=n;} for(i=0;i<10;i++) printf("%d\n",a[i]); } 帮我看一下啊 在机上调试不出来 我想要的结果 这是一个用插入排序法对输入的数进行排序 |
地主 发表时间: 04-04-04 12:56 |
![]() | 回复: sniper167 [sniper167] ![]() |
登录 |
你这个好难看懂,写的时候注意格式 用c实现的插入排序法,先输入10个数,然后利用插入排序法进行排序,将结果输出。 #include "stdio.h" #include "conio.h" main() { int a[10],r[11]; int *p; int i,j; for(i=0;i<10;i++) { p=&a[i]; printf("please scan the NO: %d\n",i); scanf("%d",p); r[i+1]=a[i]; } r[0]=1; for(i=2;i<=10;i++) { r[0]=r[i]; j=i-1; while(r[j]>r[0]) { r[j+1]=r[j]; j--; } r[j+1]=r[0]; } for(i=1;i<=10;i++) {p=&r[i];printf("form min to max the NO: %d value=%d\n",i,*p);} getch(); } |
B1层 发表时间: 04-04-04 15:00 |
![]() | 回复: lida1818 [lida1818] ![]() |
登录 |
#include <stdio.h> main() { int a[10],i,n,j,t; a[0]=4; a[1]=3; for(i=2;i<10;i++) { printf("a[%d]=",i); scanf("%d",&a[i]); j=i-1,t=i,n=a[i]; while(n>a[j]&&j>-1) { a[t]=a[j],a[j]=n,t--,j--; } } for(i=0;i<10;i++)printf("%d\n",a[i]); getch(); } |
B2层 发表时间: 04-04-04 19:48 |
![]() | 回复: lovejiang [lovejiang] ![]() |
登录 |
不错同意哈都不会老兄的 你的程序很容易懂 我那个程序好像没有为a[0]划界 我把它改成这样就可以了 呵呵烟雨平生大哥的程序也容易懂 多谢了啊 #include <stdio.h> main() { int a[10],i,n,j; a[0]=4; a[1]=3; for(i=2;i<10;i++) {printf("a[%d]=",i); scanf("%d",&a[i]); j=i; n=a[i]; while(n>a[j-1]){ a[j]=a[j-1]; if(j-1==0)a[0]=n; else j--;} a[j]=n;} for(i=0;i<10;i++) printf("%d\n",a[i]); } [此贴被 lovejiang(lovejiang) 在 04月04日20时31分 编辑过] [此贴被 lovejiang(lovejiang) 在 04月04日20时44分 编辑过] |
B3层 发表时间: 04-04-04 20:26 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号