设链表中的结点是NODE类型的结构体变量,且有NODE*p;为了申请一个新结点,并由p指向该结点,可用以下语句()。
第1题:
有以下程序段 typedef struct node { int data; struct node *next; } *NODE; NODE p; 以下叙述正确的是( )。
A.p是指向struct node结构变量的指针的指针
B.NODE p;语句出错
C.p是指向struct node结构变量的指针
D.p是struct node结构变量
第2题:
以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项
#include <stdlib.h>
struct node
{char data; struct node *next;};
(48) CreatList(char*s),
{struct node *h,*p,*q;
h=(struct node*)malloc(sizeof(struct node));
p=q=h;
while(*s!="\0")
{ p=(struct node*)malloc(sizeof(struct node));
p->data= (49) ;
q->next=p;
q= (50) ;
s++;
}
p->next="\0";
return h;
}
main()
{ char str[]="link list";
struct node*head;
head=CreatList(str);
…
}
(1)
A.char*
B.struct node
C.struct node*
D.char
第3题:
有以下程序段
typedef struct node { int data; struct node *next; } *NODE;
NODE p;
以下叙述正确的是
A)p 是指向 struct node 结构变量的指针的指针
B)NODE p ;语句出错
C)p 是指向 struct node 结构变量的指针
D)p 是 struct node 结构变量
第4题:
针对以下C语言程序,请按要求回答问题。
已知link. c源程序如下:
/*link. c程序对单向链表进行操作,首先建立一个单向链表,然后根据用户的选择可以对其进行插入结点、删除结点和链表反转操作*/
include<stdio. h>
include<stdlib. h>
typedef struct list_node * list_pointer; //定义链表指针
typedef struct list_node{ //定义链表结构
int data;
list_pointer link;
}list_node;
//用到的操作函数
list_pointer create(); //建立一个单向链表
void insert(list_pointer * p_ptr,list_pointer node); //在node后加入一个新的结点
void delete_node(list_pointer * p_ptr,list_pointer trail,list_pointer node);
//删除前一个结点是trail的当前结点node
void print(list_pointer * p_ptr); //打印链表结点中的值
list_pointer invert(list_pointer lead); //反转链表
int main()
{
list_pointer ptr=NULL;
list_pointer node,trail;
list_pointer * P=&ptr;
int choose,location,i;
printf("you should create a link first:\n");
//建立一个单向链表
prt=create(); //ptr指向链表的第一个结点
print(ptr);
//根据用户的不同选择进行相应的操作:
printf("input number 0,you can quit the program\n");
printf("input number 1,you can insert a new node to link\n"):
printf("input number 2,you can delete a node from the link\n");
printf("input number 3,you can invert the link\n"):
printf("please input you choice\n");
scanf("%d",&choose);
while(choose!=0){
switch(choose){
case 1:
i=1:
while(i<location){
node=node->link;
i++:
}
insert(p,node); //p为指向ptr的指针
print(ptr);
break;
case 2:
printf("you will delete a node from the link\n");
printf("please input the location of the node:\n");
scanf("%d",&location):
node=ptr;
if(location==1)
trail=NULL;
trail=ptr;
i=1:
while(i<location){
trail=trail->link:
i++:
}
node=trail->link;
delete_node(p,trail,node);
print(ptr);
break;
case 3:
printf("you will invert the link\n");
ptr=invert(ptr);
print(ptr);
break;
default;
break;
return -1;
}
printf("please input you choice\n");
scanf("%d". &choose):
}
return 0;
//根据用户的输入值建立一个新的单向链表:
list_pointer create()
{
int i,current,length;
list_pointer p1,p2,head;
printf("please input the node number of the link:\n");
scanf("%d". &length):
printf("the number of the link is:%d",length);
printf("please input the data for the link node:\n");
i=0;
p1=p2=(list_pointer)malloc(sizeof(list_node));
head=p1;
for(i=1;i<length;i++){
scanf("%d",&current);
p1->data=current;
p2->link=p1;
p2=p1;
p1=(list_pointer)malloc(sizeof(list_node));
}
p2->link=NULL;
return head;
}
画出主函数main的控制流程图。
第5题:
以下程序中函数fun的功能是:构成一个如图所示的带头结点的单词链表,在结点的数据域中放入了具有两个字符的字符串。函数disp的功能是显示输出该单链表中所有结点中的字符串。请填空完成函数disp。[*]
include<stdio.h>
typedef struct node /*链表结点结构*/
{char sub[3];
struct node *next;
}Node;
Node fun(char s) /*建立链表*/
{ … }
void disp(Node *h)
{ Node *
第6题:
有以下结构体说明和变量定义,如图所示,指针p、q、r分别指向此链表中的三个连续节点。 struct node {int data;struct node*next;}*P,*q,*r; 现要将q所指节点从链表中删除,同时要保持链表的连续,
以下不能完成指定操作的语句是( )。
A.p->next=q->next;
B.p->next=P->next->next;
C.p->next=r;
D.p=q->next;
第7题:
有以下结构体说明和变量的定义,且指针p指向变量a,指针q指向变量b。则不能把结点b连接到结点a之后的语句是
struct node
{ char data;
struct node *next;
} a,b,*p=&a,*q=&b;
A.a.next=q;
B.p.next=&b;
C.p->next=&b;
D.(*p).next=q;
第8题:
函数 main() 的功能是 : 在带头结点的单链表中查找数据域中值最小的结点 . 请填空
#include <stdio.h>
struct node
{ int data;
struct node *next;
};
int min(struct node *first)/* 指针 first 为链表头指针 */
{ strct node *p; int m;
p=first->next; m=p->data;p=p->next;
for(;p!=NULL;p= _[20]_______ )
if(p->data<m) m=p->data;
return m;
}
第9题:
在C语言中,可以用typedef声明新的类型名来代替已有的类型名,比如有学生链表结点: typedef struct node{ int data; struct node * link; }NODE, * LinkList; 下述说法正确的是______。
A.NODE是结构体struct node的别名
B.* LinkList也是结构体struct node的别名
C.LinkList也是结构体struct node的别名
D.LinkList等价于node*
第10题:
函数min()的功能是:在带头结点的单链表中查找数据域中值最小的结点。请填空
include <stdio.h>
struct node
{ int data;
struct node *next;
};
int min(struct node *first)/*指针first为链表头指针*/
{ struct node *p; int m;
p=first->next; re=p->data; p=p->next;
for( ;p!=NULL;p=【 】)
if(p->data<m ) re=p->data;
return m;
}