求救!帮我改改这个程序!怎样把它改成一个插入排序的演示程序
#include<stdio.h>#include<graphics.h>
#include <stdlib.h>
#define N 8
main()
{ int a[N],t;
Init(a,t);
put(a,N);
close();
exit(0);
}
sort(int a[],int n)
{ int i,j,t;
for(i=0;i<=n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[j]<a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
Init(int a[])
{ int i=0,t=0,k=0;
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"");
randomize();
setcolor(GREEN);
settextstyle(0,0,2);
for(i=0;i<N;i++)
a[i]=random(100);
sort(a,N);
for(i=0;i<N;i++)
printf("%-3d",a[i]);
printf("\n");
printf("you want to charu:");
scanf("%d,",&t);
for(i=0;i<N;i++)
{
if(t<a[i])
{
for(k=N;k>=i;k--)
a[k+1]=a[k];
a[i]=t;
break;
}
}
sort(a,N+1);
for(i=0;i<=N;i++)
printf("%-3d",a[i]);
printf("\n");
cleardevice();
}
close()
{getch();
closegraph();
}
put(int a[],int n)
{ int i;
char num[5];
setcolor(GREEN);
settextstyle(0,0,2);
for(i=0;i<=n;i++)
{ sprintf(num,"%2d",a[i]);
outtextxy(90+i*50,150,num);
}
settextstyle(0,0,1);
setcolor(BLUE);
outtextxy(200,250,"anykey to continue");
getch();
}