请C语言高手帮忙!要求用最简单的TURBOC2编写!

(1)顺序表中原有数据个数为10个,依次是{1,3,5,7,12,45,67,89,92,99}。(2)需要插入的数据e值为25。(3)注意表长的变化。(4)有序表的插入... (1)顺序表中原有数据个数为10个,依次是{1,3,5,7,12,45,67,89,92,99}。
(2)需要插入的数据e值为25。
(3)注意表长的变化。
(4)有序表的插入,需要分两步完成:第一步确定插入位置,第二步在插入位置上插入指定的数据。
展开
 我来答
匿名用户
2008-09-17
展开全部
//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>

typedef struct no{
int d;
struct no *next;
} node;

node *init(void)
{
const int a[]={1,3,5,7,12,45,67,89,92,99};
int i;
node *t,*b;
b=malloc(sizeof(node));
b->next =NULL;
for (i = 9; i>=0; --i) {
t=b;
b->d=a[i];
if (i) {
b=malloc(sizeof(node));
b->next =t;
}
}
return b;
}
void ins(node *s,int n)
{
node *t=s,*inp=malloc(sizeof(node));
inp->d=n;
while (1)
{

if (s!=NULL&&n>s->d) {
t=s;
s=s->next;
}
else{
inp->next =s;
t->next =inp;
break;
}

}
}
int main(void)
{
node *cs,*t;
cs=init(); /*初始化链表*/
t=cs;
while (t) /*输出原始链表*/
{
printf("%d ",t->d);
t=t->next;
}
ins(cs,25); /*插入*/
putchar(10);
while (cs) /*输出输入后的结果*/
{
printf("%d ",cs->d);
cs=cs->next;
}
return 0;
}
//---------------------------------------------------------------------------
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Busanhaeng
2008-09-17 · TA获得超过612个赞
知道小有建树答主
回答量:200
采纳率:0%
帮助的人:310万
展开全部
#include "stdio.h"
#define e 25
main()
{
int i,n[11]={1,3,5,7,12,45,67,89,92,99} ;
int count;
for(i=0;i<10;i++)
{
if(n[i]<=e)
count=++i;
}
for(i=10;i>=count;i--)
n[i+1]=n[i];
n[count]=e;
printf("e cha ru wei zhi is:%d\n",count+1);
for(i=0;i<11;i++)
printf("%d ",n[i]);
getch( );
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式