编程C:使用“监视哨”方法实现顺序表查找,并说明监视哨的作用
答案:2 悬赏:20 手机版
解决时间 2021-01-28 16:58
- 提问者网友:鼻尖触碰
- 2021-01-27 16:22
编程C:使用“监视哨”方法实现顺序表查找,并说明监视哨的作用
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-01-27 17:22
你说的“监视哨”就是“哨兵”吧,顺序表查找似乎不需要,“哨兵”多用在排序中,下面给出一个实例带详注。我发的写的程序都是经过验证无误的。本程序在win-tc和Dev-c++下运行通过。
#include
#include
#define MAX 255
int R[MAX];
void Insert_Sort(int n)
{
int i,j;
for(i=2;i<=n;i++)
if(R[i] {
R[0]=R[i];j=i-1;
do{
R[j+1]=R[j];
j--;
}while(R[0] R[j+1]=R[0];
}
}
main()
{
int i,n;
clrscr();
puts("Please input total element number of the sequence:");
scanf("%d",&n);
if(n<=0||n>MAX)
{
printf("n must more than 0 and less than %d.\n",MAX);
exit(0);
}
puts("Please input the elements one by one:");
for(i=1;i<=n;i++)
scanf("%d",&R[i]);
puts("The sequence you input is:");
for(i=1;i<=n;i++)
printf("%4d",R[i]);
Insert_Sort(n);
puts("\nThe sequence after insert_sort is:");
for(i=1;i<=n;i++)
printf("%4d",R[i]);
puts("\n Press any key to quit...");
getch();
}
#include
#include
#define MAX 255
int R[MAX];
void Insert_Sort(int n)
{
int i,j;
for(i=2;i<=n;i++)
if(R[i]
R[0]=R[i];j=i-1;
do{
R[j+1]=R[j];
j--;
}while(R[0]
}
}
main()
{
int i,n;
clrscr();
puts("Please input total element number of the sequence:");
scanf("%d",&n);
if(n<=0||n>MAX)
{
printf("n must more than 0 and less than %d.\n",MAX);
exit(0);
}
puts("Please input the elements one by one:");
for(i=1;i<=n;i++)
scanf("%d",&R[i]);
puts("The sequence you input is:");
for(i=1;i<=n;i++)
printf("%4d",R[i]);
Insert_Sort(n);
puts("\nThe sequence after insert_sort is:");
for(i=1;i<=n;i++)
printf("%4d",R[i]);
puts("\n Press any key to quit...");
getch();
}
全部回答
- 1楼网友:话散在刀尖上
- 2021-01-27 18:55
监视哨的作用:
无需判断是否越界.
无需判断是否越界.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯