更多"单向链表的每一个节点都有一个指向它的后续节点的指针link,现有节点p"的相关试题:
[单项选择]单向链表的每一个结点都有一个指向它的后续结点的指针link,现有结点p和q,结点q在结点p的前面,要删除结点P,正确的操作应该是()
A. q↑.link:=p↑.link;
B. p↑.link:=q↑.link;
C. q↑.link:=p;p↑.link:=q;
D. q:=p↑.link;p↑.link:=q↑.link;
[填空题]下面程序中函数creat用于建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾,单向链表的头指针作为函数值返回。将程序补充完整。
#include<stdiao.h>
struct list
char data; struct list * next;;
struct list * creat( )
struct list *h,*p,*q; char ch;
h= 【18】 malloc(sizeof(struct list));
p=q=h;ch=getchar( );
while(ch!=’’)
p= 【19】 malloc(sizeof(struct list));
p->data=ch;q->next=p;q=p;ch=getchar( );
p->next=’/0’;
【20】 ;
[填空题]以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回。请填空。
#include <stdio.h>
struct list
{ char dara;
struct list *next;
};
struct list *creat( )
{ struct list *h,*p,*q;
char ch;
h= (struct list (*) malloc (sizeof (struct list));
______;
ch=getchar( );
while(ch!=’’)
{ p=(struct list*) malloc) sizeof (struct list));
p->data=ch;
______;
q=p;
ch=getchar( );
}
p->next=’/0’;
______:
}
[填空题]以下函数creat用来建立一个带头结点的单向链表,新产生的结点是插在链表头的
末尾。单向链表的头指针作为函数值返回。请填空。
# include<stdio.h>
struct list
char data;
struct list * next;
;
struct list * creat;
struct list * h,* p,* q;
char ch;
h=(______)malloc ( sizeof(struct list));
p=q=h;
ch=getchar( );
while(ch!=’’)
p=(______)mallco(sizeof(struct list));
p->data=ch;
q->next=p;
q=p;
ch=getchar( );
p->next=’/0’;
______;
[单项选择]若在单向链表上,除访问链表中所有节点外,还需在表尾频繁插入节点,那么采用______最节省时间。
A. 仅设尾指针的单向链表
B. 仅设头指针的单向链表
C. 仅设尾指针的单向循环链表
D. 仅设头指针的单向循环链表
[单项选择]与单向链表相比,双向链表()
A. 需要较少的存储空间
B. 遍历元素需要的时间较短
C. 较易于访问相邻结点
D. 较易于插入和删除元素
[填空题]以下程序段用于构成一个简单的单向链表。请填空。
struet STRU
int x,y;
float rate;
【14】 p;
a,b;
a.x=0; a.y=0;a.rate=0;a.p=&b;
b.x=0;b.y=0;b.rate=0;b.p=NULL;
[简答题]给定程序中,函数fun的功能是将不带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 6
typedef struct node {
int data;
struct node *next;
} NODE;
void fun(NODE *h)
{ NODE *p, *q; int t;
p = h;
while (p) {
q = __1__ ;
while (__2__)
{ if (p->data > q->data)
{ t = p->data; p->data = q->data; q->data = t; }
q = q->next;
}
p = __3__ ;
}
}
NODE *creatlist(int a[])
{ NODE *h,*p,*q; int i;
h=NULL;
for(i=0; idata=a[i];
q->next = NULL;
if (h == NULL) h = p = q;
else { p->next = q; p = q; }
}
return h;
}
void outlist(NODE *h)
{ NODE *p;
p=h;
if (p==NULL) printf("The list is NULL!/n");
else
{ printf("/nHead ");
do
{ printf("->%d", p->data); p=p->next; }
while(p!=NULL);
printf("->End/n");
}
}
main( )
{
[简答题]已知一个单向链表结点的数据结构定义如下:
struct node
{
char data;
struct node *next;
};
函数struct node *cre (char *s)的功能是:根据s指向的字符串建立一个结点类型为struct node头指针为h的单向链表,使h链表中各结点的数据域分别存储s指向字符串中所有大写字母的编码,函数返回h链表首结点的地址.例如,若s指向的字符串为"3Aa26Bx5Y9",则h指向的链表如下图所示。
#include
#include
struct node
{
char data;
struct node *next;
};
struct node *cre(char *s)
{
struct node *p,*p1,*h;
if (___(27)___) return NULL;
h=p1=p=(struct node *)malloc(sizeof(struct node)) ;
p->data=*s ;
s++;
while (*s)
{
if(*s>=’A’ && *s<=’Z’)
{
p= (struct node *) malloc (sizeof (struct node)) ;
p->data=*s ;
___(28)____ = p;
p1=p ;
}
s++;
}
___ (29)___ =NULL;
___(30)___;
}
void print(struct node *h)
{
struct node *p=h;
while (p!=NULL)
{ printf ("%3c", p->d
[填空题]已知bead指向一个带头结点的单向链表,链表中每个结点包含数据域(data)和指针域(next),数据域为整型。以下函数求出链表中所有连接点数据域的和值作为函数值返回。请在横线处填入正确内容。
int data; struct link *next;
main( )
struct link *head;
sam(______);
stmct link *p;int s=0;
p=head->next;
while(p)s+=p->data;p=p->next;
return(s);
[简答题]下列给定程序中,已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。
请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <stdlib .h >
#define N 8
typedef struct list
int data;
struct list * next;
SLIST;
void fun(SLIST * h, int x)
SLIST * p, * q, * s;
s=(SLIST *) malloc (sizeof
(SLIST));
/********** found********** /
s->data= (1) ;
q=h;
p=h->next;
while(p!=NULL && x >p->data)
/********** found********** /
q= (2) ;
p=p->next;
s->next=p;
/********** found********** /
q->next= (3) ;
SLIST * creatlist(int * a)
SLIST * h, * p, * q; int i;
h=p=(SLIST *)malloc (sizeof
(SLIST));
for(i=0; i<N; i++)
q=(SLIST *)malloc (sizeof
(SLIST));
q->data=a[i]; p->next=q; p=q;
[简答题]
下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun( )的功能是:将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并作为函数值返回。
其累加和通过函数值返回main( )函数。例如,若n=5,则应输出8.391667。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#include<stdiib.h>
typedef struct aa
int data;
struct aa *next;
NODE;
int fun(NODE *h)
int sum=0;
NODE *P;
/**********found**********/
p=h;
while(P->next)
if(p->data%2==0)
sum+=p->data;
/**********found**********/
p=h->next;
return sum;
NODE *creatlink(int n)
NODE *h, *p, *s, *q;
int i, x;
h=p=(NODE *)malloc(si zeof(NODE));
for(i=1; i<=n; i++)
s=(NODE *)malloc(sizeof(NODE));
s->data=rand( )%16;
s->next=p->next;
p->next=s;
p=p->next;
p->next=NULL;
return h;
outlink(NODE *h, FILE *Pf)
[填空题]以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(键表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include<stdio.h>
struct list int data;struct list*next;;
struct list*creatlist( )
struct list*p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
p=(struct list*)malloc(sizeof(struct list));
【19】 =a;q->next=p; 【20】 =p;scanf("%d",&a);
p->next=’/0’;return(ph);
main( )
struct list * head;head=creatlist( );
[填空题]以下程序的功能是建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include <stdio.h>
struct list int data;struct list *next;;
struct list *creatlist( )
struct list *p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
p=(struct list*)malloc(sizeof(struct list));
______=a;q->next=p;______=p;scanf("%d",&a);
p->next=’/0’;return(ph);
main( )
stuct list * head;head=creatlist( );