你可能喜欢
填空题
设线性链表的存储结构如下:
struct node
{ELEMTP data; /*数据域*/
struct node *next; /*指针域*/
}
试完成下列建立单链表的算法。
creat()
{char var;
head=(struct node *)malloc(sizeof(struct node));
head->next= () ;
while((var=getchar())!=‘\n’){
ptr=( struct node *)malloc(sizeof(struct node));
ptr->data= var ;ptr->next=head->next;
head->next= ptr ;
}
}
填空题
设线性链表的存储结构如下:
struct node
{ELEMTP data; /*数据域*/
struct node *next; /*指针域*/
}
试完成下列在链表中值为x的结点前插入一个值为y的新结点。如果x值不存在,则把新结点插在表尾的算法。
void inserty(struct node *head,ELEMTP x,ELEMTP y)
{s=(struct node *)malloc(sizeof(struct node));
();
if(){s->nexr=head;head=s;}
else {
q=head;p=q->next;
while(p->dqta!=x&&p->next!=NULL){q=p;()}
if(p->data= = x){q->next=s;s->next=p;}
else{p->next=s;s->next=NULL;}
}
}
填空题
设顺序存储的线性表存储结构定义为:
struct sequnce
{ELEMTP elem[MAXSIZE];
int len; /*线性表长度域*/
}
将下列简单插入算法补充完整。
void insert(struct sequnce *p,int i,ELEMTP x)
{v=*p;
if(i<1)||(i>v.len+1)printf(“Overflow“);
else {
for(j=v.len;();j- -)();
v.elem[i]= () ;v.len=();
}
}