更多"单向链表中往往含有一个头结点,该结点不存储数据元素,一般令链表的头指针"的相关试题:
[填空题]
假设某个不设头指针的无头结点单向循环链表的长度大于1,S为指向链表中某个结点的指针。算法f30的功能是,删除并返回链表中指针S所指结点的前驱。请在空缺处填入合适的内容,使其成为完整的算法。
typedef struct node{
DataType data;
struct node *next;
}*LinkList;
DataType f 30(LinkList s){
LinkList pre,p;
DataType e;
pre=s;
p=s—>next;
while( (1) ){
pre=p;
(2) ;
}
pre—>next= (3) ;
e=p—>data;
free(p);
return e;
}
(1)
[填空题]以下函数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’;
______;
[填空题]以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-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));
[14] =a;q->next=p; [15] =p;scanf("%d",&a);}
p->next=’/0’;return(ph);}
main( )
{stuct list * head;head=creatlist( );}
[填空题]以下程序中函数 fun 的功能是:构成一个如图所示的带头结点的单向链表,在结点 的数据域中放入了具有两个字符的字符串。函数 disp 的功能是显示输出该单向链表 中所有结点中的字符串。请填空完成函数 disp。
head
ab cd ef /0
#include
typedef struct node /*链表结点结构*/
{ char sub[3];
struct node *next;
}Node;
Node fun(char s) /* 建立链表*/
{ …… }
void disp(Node *h)
{ Node *p;
p=h->next;
while(= _______ )
{ printf("%s/n",p->sub);p= _______ ; }
}
main( )
{ Node *hd;
hd=fun( ); disp(hd);printf("/n");
}
[填空题]以下程序中函数fun的功能是:构成一个如图所示的带头结点的单向链表,在结点的数据域中放入了具有两个字符的字符串。函数disp的功能是显示输出该单链表中所有结点中的字符串。请填空完成函数
disp。
#include
typedef struct node/*链表结点结构*/
{char sub[3];
struct node * next;
}Node;
Node fun(char S) /*建立链表*/
{ ……}
void disp(Node *h)
{Node*P;
P=h->next;
while(【 】)
{printf("%s\n",P->sub);P=【 】; }
}
main( )
{Node *hd;
hd=fun( );disp(hd);prinff("\n");
}
[填空题]下面程序中函数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】 ;
[填空题]请补充fun函数,该函数的功能是:将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef Struct node
int data;
struct node *next;
NODE;
void fun(NODE *h)
NODE *p, *q, *r;
p= (1) ;
if ( (2) ) return;
q=P->next;
P->next=NULL;
while (q)
r=q->next;
q->next=p;
p=q;
q= (3) ;
h->next=p;
NODE *creatlis (int a[])
NODE *h, *p, *q; int i;
h= (NODE *)malloc(sizeof(NODE));
h>next=NULL:
for(i=0; i<N; i++)
q=(NODE *)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h->next==NULL)
h->next=p=q;
else
p->next=q; p=q;
return h;
void ou list(NODE *h)
NODE *p;
p=h->next;
if(p==NU
[单项选择]以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请为下划线处选择正确的选项。
#include < stdlib. h >
stuct node
char data; struct node * next; ;
( ) CreatList(char * s)
struet node * h, * p, * q;
h = (struet node * ) ma]loc(sizeof(struct node) );
p=q=h;
while( * s! =’/0’)
p = ( struct node * ) ma]loc ( sizeof( struct node) );
p- >data= *s; q- >next=p; q=p;
s++;
p- > next =’/0’;
return h
main( )
char str[ ] = "link list";
struet node * head;
head = CreatList (str);
A. char *
B. struet node
C. struct node *
D. char