链表题:一个链表的结点结构struct Node{int data ;Node *next ;};typedef struct Node Node ;(1)已知链表的头结点head,写一个函数把这个链表逆序( Intel)

链表题:一个链表的结点结构

struct Node

{

int data ;

Node *next ;

};

typedef struct Node Node ;

(1)已知链表的头结点head,写一个函数把这个链表

逆序( Intel)


相关考题:

设计递归算法,判断二叉树t是否满足小根堆的特点。二叉链表的类型定义如下: typedef int datatype;//结点的数据类型,假设为inttypedef struct NODE *pointer;//结点指针类型struct NODE {datatype data;pointer lchild,rchild;};typedef pointer bitree;//根指针类型

以下程序把三 个 NODETYP E 型的变量链接成一个简单的链表 , 并 在 whil e 循环中输出链表结点数据域中的数据,请填空。#include stdio.hstruct node{int data; struct node *next;};typedef struct node NODETYPE;main(){ NODETYPE a,b,c,*h,*p;a.data=10;b.data=20;c.data=30;h=a;a.next=b;b.next=c;c.next='\0';p=h;while(p){printf("%d,", p-data); 【 1 5 】 ; }printf("\n");}

以下程序把三个NODETYPE型的变量链接成一个简单的链表,并在while循环中输出链表结点数据域中的数据,请填空#include stdio.hstruct node{int data; struct node *next;};typedef struct node NODETYPE;main(){NODETYPE a,b,c,*h,*p;a. data=10;b.data=20;c.data=30;h=a;b. next=b;b.next=c;c.next=’\0’;p=h;while(p){printf(“d”,p-data);【15】;}}

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

以下程序中函数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 *

在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*

函数min()的功能是:在带头结点的单链表中查找数据域中值最小的结点。请填空includestruc 函数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;}

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】函数sort (NODE *head)的功能是;用冒泡排序法对单链表中的元素进行非递减排序。对于两个相邻结点中的元素,若较小的元素在前面,则交换这两个结点中的元素值。其中,head指向链表的头结点。排序时,为了避免每趟都扫描到链表的尾结点,设置一个指针endptr,使其指向下趟扫描需要到达的最后一个结点。例如,对于图4-1(a)的链表进行一趟冒泡排序后,得到图4-1(b)所示的链表。链表的结点类型定义如下:typedef struct Node {int data;struct Node *next;} NODE;【C语言函数】void sort (NODE *head){ NODE *ptr,*preptr, *endptr;int tempdata;ptr = head -> next;while ((1)) /*查找表尾结点*/ptr = ptr -> next;endptr = ptr; /*令endptr指向表尾结点*/ptr =(2);while(ptr != endptr) {while((3)) {if (ptr->data > ptr->next->data){tempdata = ptr->data; /*交换相邻结点的数据*/ptr->data = ptr->next->data;ptr->next->data = tempdata;}preptr =(4); ptr = ptr -> next;}endptr =(5); ptr = head->next;}}

以下程序的功能是:建立一个带有头结点的甲—向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项。#include <stdlib.h>struct node{ char data; struct node *next: };(1) 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 = (2) ;q->next = p;q - (3) ;S++;}p->next='\0';return h;}main(){char str[]="link list";struct node *head;head = CreatList(str);}(1)A.char*B.struct nodeC.struct node*D.char

以下程序把三个NODEIYPE型的变量链接成—个简单的链表,并在while循环中输出链表结点数据域中的数据。请填空。include<stdio.h>struct node{ int data;struct node*next;);typedef struct node NODETYPE;main(){ NODETYPEa,b,c,*h,*p;a.data=10;b.data=20;c.data=30;h=a;anext=b;b.next=c;c,next='\0';p=h;while(p){printf("%d,",p->data):【 】;}printf("\n");}

以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。#include stuct node{ char data; struct node *next;}; (48) CreatLis(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=CreatLis(str); ...}A.char *B.struct nodeC.struct node*D.char

阅读以下说明和C语言函数,将应填入(n)。【说明】已知包含头结点(不存储元素)的单链表的元素已经按照非递减方式排序,函数 compress(NODE*head)的功能是去掉其中重复的元素,使得链表中的元素互不相同。处理过程中,当元素重复出现时,保留元素第一次出现所在的结点。图2-1(a)、(b)是经函数compress()处理前后的链表结构示例图。链表的结点类型定义如下:typedef struct Node{int data;struct Node *next;}NODE;【C语言函数】void compress(NODE *head){ NODE *ptr,*q;ptr= (1); /*取得第一个元素结点的指针*/while( (2) ptr->next) {q=ptr->next;while(q(3)) { /*处理重复元素*/(4)q->next;free(q);q=ptr->next;}(5) ptr->next;}/*end of while */}/*end of compress*/

下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。请改正程序指定部位的错误,使它能得到正确结果。[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。[试题源程序]include<stdio.h>include<stdlib.h>typedef struct aa{int data;struct aa *next;}NODE;fun(NODE *h){int max=-1;NODE *p;/***********found************/p=h;while(p){if(p->data>max)max=p->data;/************found************/p=h->next;}return max;}outresult(int s, FILE *Pf){fprintf(pf, "\nThe max in link: %d\n", s);}NODE *creatlink(int n, int m){NODE *h, *p, *s, *q;int i, x;h=p=(NODE *)malloc(sizeof(NODE));h->data=9999;for(i=1; i<=n; i++){s=(NODE *)malloc(sizeof(NODE));s->data=rand()%m; s->next=p->next;p->next=s; p=p->next;}p->next=NULL;return h;}outlink(NODE *h, FILE *pf){NODE *p;p=h->next;fprintf(Pf, "\nTHE LIST:\n\n HEAD");while(P){fprintf(pf, "->%d", P->datA); p=p->next;}fprintf(pf, "\n");}main(){NODE *head; int m;head=cteatlink(12,100);outlink(head, stdout);m=fun(head);printf("\nTHE RESULT"\n");outresult(m, stdout);}

以下程序中函数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 *p;p=h->next;while([ ]){printf("%s\n",p->sub);p=[ ];}}main(){ Node *hd;hd=fun(); disp(hd);printf("\n");}

[说明]已知包含头节点(不存储元素)的单链表的元素已经按照非递减方式排序,函数compress(NODE *head)的功能是去掉其中重复的元素,使得链表中的元素互不相同。处理过程中,当元素重复出现时,保留元素第一次出现所在的节点。图8-29(a)、(b)是经函数compress( )处理前后的链表结构示例图。链表的节点类型定义如下:typedef struct Node {int data;struct Node *next;}NODE;[C语言函数]void compress(NODE *head){NODE *ptr, *q;ptr= (1) ; /*取得第一个元素节点的指针*/while( (2) ptr->next) {q=ptr ->next;while(q (3) ){/*处理重复元素*/(4) =q ->next;free(q);q=ptr->next;}(5) =ptr->next;} /*end of while*/} /*end of compress*/

有以下结构说明和变量定义,指针p、q、r分别指向链表中的3个连续结点。 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;

下面正确定义了仅包含一个数据成员info的单链表的结点类型。struct node { int info;struct node next;} () 此题为判断题(对,错)。

以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请填空。 #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.*sB.sC.*s++D.(*s)++

下面程序的功能是建立一个有 3 个 结 点的单向循环链表,然后求各个 结 点数值域 data 中数据的和。请填空。include stdio.hinclude stdlib.hstruct NODE{ int data;struct NODE *next;};main(){ struct NODE *p,*q,*r;int sum=0;p=(struct NODE*)malloc(sizeof(struct NODE));q=(struct NODE*)malloc(sizeof(struct NODE));r=(struct NODE*)malloc(sizeof(struct NODE));p-data=100; q-data=200; r-data=200;p- next =q; q- next =r; r- next =p;sum=p-data+p-next-data+r-next-next 【 19 】 ;printf("%d\n",sum);}

试题四(共 15 分)阅读以下说明和 C 语言函数,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]已知包含头结点(不存储元素)的单链表的元素已经按照非递减方式排序,函数compress(NODE *head)的功能是去掉其中重复的元素,使得链表中的元素互不相同。处理过程中,当元素重复出现时,保留元素第一次出现所在的结点。图4-1(a)、(b)是经函数 compress()处理前后的链表结构示例图。链表的结点类型定义如下:typedef struct Node {int data;struct Node *next;}NODE;[C 语言函数]void compress(NODE *head){ NODE *ptr,*q;ptr = (1) ; /* 取得第一个元素结点的指针 */while ( (2) ptr - next) {q = ptr - next;while(q (3) ) { /* 处理重复元素 */(4) = q - next;free(q);q = ptr - next;}(5) = ptr - next;}/* end of while */}/* end of compress */

函数main()的功能是:在带头结点的单链表中查找数据域中值最小的结点.请填空#include stdio.hstruct 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-datam) m=p-data;return m;}

设线性链表的存储结构如下: 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 ; } }

设某带头结头的单链表的结点结构说明如下:typedef struct nodel{int data struct nodel*next;}node;试设计一个算法:void copy(node*headl,node*head2),将以head1为头指针的单链表复制到一个不带有头结点且以head2为头指针的单链表中。

设线性链表的存储结构如下: 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!=xp-next!=NULL){q=p;()} if(p-data= = x){q-next=s;s-next=p;} else{p-next=s;s-next=NULL;} } }

问答题下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun()的功能是:将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并作为函数值返回。  请改正函数fun中的错误,使它能得出正确的结果。  注意:部分源程序在文件MODII.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!  试题程序:#include #include #include typedef struct aa{ int data; struct aa *next;}NODE;int fun(NODE *h){ int sum=0; NODE *p; p=h-next; /*********found*********/ 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; int i; h=p=(NODE *)malloc(sizeof(NODE)); for(i=1;idata=rand()%16;  s-next=p-next;  p-next=s;  p=p-next; } p-next=NULL; return h;}outlink(NODE *h){ NODE *p; p=h-next; printf("The LIST: HEAD"); while(p) {  printf("-%d",p-data);  p=p-next; } printf("");}main(){ NODE *head; int sum; system("CLS"); head=creatlink(10); outlink(head); sum=fun(head); printf("SUM=%d",sum);}

填空题设线性链表的存储结构如下: 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!=xp-next!=NULL){q=p;()} if(p-data= = x){q-next=s;s-next=p;} else{p-next=s;s-next=NULL;} } }

填空题设线性链表的存储结构如下: 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 ; } }