请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)有序表的插入,需要分两步完成:第一步确定插入位置,第二步在插入位置上插入指定的数据。 展开
(2)需要插入的数据e值为25。
(3)注意表长的变化。
(4)有序表的插入,需要分两步完成:第一步确定插入位置,第二步在插入位置上插入指定的数据。 展开
2个回答
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;
}
//---------------------------------------------------------------------------
#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;
}
//---------------------------------------------------------------------------
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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( );
}
#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( );
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询