以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项#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=(stru

题目

以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项

#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


相似考题
参考答案和解析
正确答案:C
更多“以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结 ”相关问题
  • 第1题:

    以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请填空。 #include <stdlib.h> stuct node { char data; struet node * next; }; stntct node * CreatList(char * s) { struet 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 = ( ) q- >next=p; q=p; a++; p- > next ='\0'; return h; } main( ) { char str[ ]= "link list"; struet node * head; head = CreatList(str);

    A.*s

    B.s

    C.*s++

    D.(*s)++


    正确答案:A
    解析:本题要求建立一个stmctnode类型的数据链表,函数CreatList将字符串"linklist"的首地址传给指针变量s,可以推断建立的链表一定与"linklist",有关,由CreatList(char*s)函数中所定义的变量及其他语句可知,h,p,q用于建立的链表,h表示头指针,p用于记录开辟的新结点,而q用作将新结点与已建立的链表相连的中间变量,所建立链表各个结点的data依次存放的是”linklist",中的各个字符,所以应填空*s。

  • 第2题:

    在单向链表中,要访问某个结点,只要知道该结点的指针即可;因此,单向链表是一种随机存储结构。


    错误

  • 第3题:

    静态链表(使用数组来存储的链表)中结点内指针指示的是_____ 。

    A.内存地址

    B.数组下标

    C.链表中下一个元素在数组中的地址

    D.右孩子地址


    链表中下一个元素在数组中的地址

  • 第4题:

    以下说法中不正确的是()。

    A双向循环链表中每个结点需要包含两个指针域

    B已知单向链表中任一结点的指针就能访问到链表中每个结点

    C顺序存储的线性链表是可以随机访问的

    D单向循环链表中尾结点的指针域中存放的是头指针


    B

  • 第5题:

    3、编写程序建立一个单向链表。链表结点中的数据为从键盘输入的一个字符串,但要求将该串字符按由小到大的顺序组织在链表中。


    #include<stdio.h> #include<stdlib.h> #defineLEN sizeof(struct Student) structStudent {long num; floatscore; structStudent *next; }; intn; structStudent *creat(void) {struct Student *head,*p1,*p2; n=0; p1=p2=( struct Student*) malloc(LEN); scanf(“%ld,%f”,&p1->num,&p1->score); head=NULL; while(p1->num!=0) {n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=(struct Student*)malloc(LEN); scanf(“%ld,%f”,&p1->num,&p1->score); } p2->next=NULL; return(head); } intmain() {struct Student *pt; pt=creat(); printf(“\nnum:%ld\nscore:%5.1f\n”,pt->num,pt->score); return 0; }