网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

写出算法的功能。int L(head){ node * head; int n=0; node *p; p=head; while(p!=NULL) { p=p->next; n++; } return(n); }


参考答案

更多 “写出算法的功能。int L(head){ node * head; int n=0; node *p; p=head; while(p!=NULL) { p=p-next; n++; } return(n); }” 相关考题
考题 ●试题三阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】函数diff的功能是:根据两个由整数(都大于-32768)按升序构成的单链表L1和L2(分别由A,B指向)构造一个单链表L3(由*r指向),要求L3中的所有整数都是L1,并且不是L2中的整数,还要求L3中的所有整数都两两不等。【函数】#include<malloC.htypedef struct node{int d;struct node *next}Node;void diff(Node *A,Node *B,Node **r){int lastnum;Node*p;*r=NULL;if(!A)return;while( (1) )if(A-dB-d){lastnum=A-d;p=(Node*)malloc(sizeof(Node));p-d=lastnum;p-next=*r; (2) ;doA=A-next;while( (3) );}else if(A-dB-d)B=B-next;else{(4) ;lastnum=A-d;while (A A-d==lastnum)A=A-next;}while(A){lastnum=A-d;p=(Node*)malloc(sizeof(Node));p-d=lastnum;(5) ;*r=p;while (A A-d==lastnum) A=A-next;}}

考题 ●试题三阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明3.1】假设以带头结点的单循环链表作非递减有序线性表的存储结构。函数deleteklist(LinkList head)的功能是删除表中所有数值相同的多余元素,并释放结点空间。例如:链表初始元素为:(7,10,10,21,30,42,42,42,51,70)经算法操作后变为:(7,10,21,30,42,51,70)【函数3.1】void deleteklist(LinkList head){LinkNode*p,*q;p=head-next;while(p!=head){q=p-next;while( (1) ){(2) ;free(q);q=p-next;}p=p-next;}}【说明3.2】已知一棵完全二叉树存放于一个一维数组T[n]中,T[n]中存放的是各结点的值。下面的程序的功能是:从T[0]开始顺序读出各结点的值,建立该二叉树的二叉链表表示。【函数3.2】#includeistream.htypedef struct node {int data;stuct node leftChild,rightchild;}BintreeNode;typedef BintreeNode*BinaryTree;void ConstrncTree(int T[],int n,int i,BintreeNode*&ptr){if(i=n) (3) ;∥置根指针为空else{ptr=-(BTNode*)malloc(sizeof(BTNode))ptr-data=T[i];ConstrucTree(T,n,2*i+1, (4) );ConstrucTree(T,n, (5) ,ptr-rightchild);}}main(void){/*根据顺序存储结构建立二叉链表*/Binarytree bitree;int n;printf("please enter the number of node:\n%s";n);int*A=(int*)malloc(n*sizeof(int));for(int i=0;i<n;i++)scanf("%d,A+i);/*从键盘输入结点值*/for(int i=0;i<n;i++)printf("%d",A[i]);ConstructTree(A,n,0,bitree);}

考题 论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)已知 link.c 源程序如下:/*link.c 程序对单向链表进行操作 , 首先建立一个单向链表 , 然后根据用户的选择可以对其进行插入节点 、删除节点和链表反转操作 */#include#includetypedef 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 的当前节点 nodevoid print(list_pointer 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");// 建立一个单向链表:ptr=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 your choice\n");scanf("%d", choose);while(choose!=0){switch(choose){case 1:printf("you will insert a node to the link\n");printf("please input the location of the node:\n");scanf("%d", location);node = ptr;i = 1;while(ilocation){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(ilocation){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 your 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\n", 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 = 0; iscanf("%d", ¤ t);p1-data = current;p2-link = p1;p2 = p1;p1 = (list_pointer) malloc(sizeof(list_node));}p2-link = NULL;return head;}……( 1 )画出主函数 main 的控制流程图。( 10 分)( 2 ) 设计一组测试用例 , 尽量使 main 函数的语句覆盖率能达到 100% 。 如果认为该函数的语句覆盖率无法达到 100% ,需说明原因。( 8 分)

考题 下面程序实现十进制向其他进制的转换。[Java程序]C1ass Node{int data;Node next;}class Transform{private Node top;publiC void print(){Node P;while(top !=null){P=top;if(P.data>9)System.out.print((char)(p.data+55));elseSystem.out.print(p.data);top=P.next;}}public void Trans(int d,int i)(//d为数字;i为进制int m;(1) n=false;Node P;while(d>0){(2) ;d=d/i;P=flew Node();if( (3) ){P.data=m;(4) ;top=P;n=true;}else{p.data=m;(5) ;toP=P;}}}}

考题 ●试题四阅读下列程序说明,将在空缺处填入正确的内容。【程序说明】定义一个多边形结构:struct polygon实现以下内容: (1) 建立该结构的链表:create函数是创建链表,每输入一个结点的数据,就把该结点加入到链表当中,它返回创建的链表的头指针。 (2) 显示链表的各个结点数据:结点数据包括:多边形顶点数、各顶点的纵横坐标、当多边形顶点数为0时,链表创建结束。 (3) 编写一个函数disp,删除链表中的所有结点。需要注意的是:要先释放结点数据内存,再删除结点,如果在释放结点数据内存单元之前删除结点,则无法找到结点数据内存单元的地址,也就无法释放数据的内存单元。【程序】#include"iostream.h"#include"iomanip.h"struct polygon{int n;int *x;int *y;polygon *next;};void Push(polygon* head,int n){polygon*newNode=new polygon;newNode=new polygon;newNode-next= (1) ;newNode-x=new int[n];newNode-y=new int[n];newNode-n= (2) ;for(int i=0;i= (3) ;i++){cout"请输入多边形各顶点x、y坐标,坐标值之间用空格分隔:";cinnewNode-x[i]newNode-y[i];}(4) =head;// 在head前不需要额外的*head=newNode;}polygon *create(){polygon*head=NULL;polygon*tail;int n;cout"请输入多边形顶点的个数(顶点个数为0时结束):";cinn;if(n==0)return (5) ;Push(head, (6) ;tail=head;cout"请输入多边形顶点的个数(顶点个数为0时结束):";cinn;while(n!=0){Push(tail-next, (7) ;//在tail-next增加结点tail=tail-next;//advance tail to point to last nodecout"请输入多边形顶点的个数(顶点个数为0时结束):";cinn;}return head;}void disp(polygon*head){int i,No=1;coutsetw (10) "x"setw (6) "y"endl;while(head!=NULL){cout"第"No"结点:"endl;for(i=0;i=head-n-1;i++)coutsetw (10) head-x[i]setw (6) head-y[i]endl;(8) ;head= (9) ;}//Match while statement}void del(polygon*head){polygon*p;while(head!=NULL){p= (10) ;head=head-next;delete p-x;delete P-y;deletep;}//Match while statement}void main(){polygon*head;head=create();disp(head);del(head);}

考题 请补充函数fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。注意:部分源程序给出如下。请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。试题程序:include<stdio. h>include<conio. h>include<stdlib. h>typedef struct ss{int data;struct ss *next;} NODE;void fun(int n,char*filename){NODE *h,*p, *s;FILE *pf;int i;h=p= (NODE *) malloc (sizeof (NODE));h->data=0;for (i=1; i {s=(NODE *)malloc (sizeof (NODE));s->data=【 】;【 】;p=【 】}p->next=NULL;if ( (pf=fopen (filename, "w") ) ==NULL){printf {"Can not open out9B.clat! ");exit (0);}p=h;fprintf (pf, "\n***THE LIST***\n");print f ("\n***THE LIST***\n")while (p){fprintf (pf, "%3d", p->data)printf ("%3d",p->data);if (p->next ! =NULL){fprintf (pf, "->");printf ("->");}p=p->next;}fprintf (pf, "\n");printf ("\n");fclose (pf);p=h;while (p){s=p;p=p->next;free (s);}}main(){char * filename="out98. dat";int n;clrscr ();printf (" \nInput n: ");scanf ("%d", n);fun (n, filename);}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[C++程序]include"ioStream.h"include"math.h"includetypedef struct node {int data;node*next;}Node;Class Transform.{DUDlic:void Trans(int d,int i); //d为数字;i为进制void print();private:Node*top;};void Transform.:Trans(int d,int i){int m,n=0;Node*P;while(d>0){(1);d=d/i;p=new Node;if(!n){p->data=m;(2);(3);n++;}else{p->data=m;(4);(5);}}}void Transform.:print(){Node*P;while(top!=NULL){p=top;if(p->data>9)cout<<data+55;elsecout<<data;top=p->next;delete p;}}

考题 针对以下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的当前结点nodevoid 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的控制流程图。

考题 阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[Java程序]ClasS Node{int data;Node next;}class Transform{private Node top;public void print(){Node p;while(top!=null){P=top;if(P.data>9)System.out.print((char)(P.data+55));elseSystem.out.print(p.data);top=p.next;}}public void Trans(int d,int i){//d为数字;i为进制int m;(1) n=false;Node p;while(d>0){(2);d=d/i;p=new Node();if( (3) ){p.data=m;(4);top=P;n=true;}else{p.data=m;(5);top=P;}}}}

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

考题 Simplify the following Boolean expression!((i ==12) || (j 15))struct Node {int value;Node* next;};1.1 Get the value of the Nth node from last node in the linked list.PARAM HEAD: the first element in the linked list:PARAM n: the number of the node counted reverselyRETURN: the value of the node, or -1 if not existsint GetValue(Node* HEAD, int n){}1.2 Delete a node WITHOUT using the HEAD pointer.PARAM p: A pointer pointed to a node in the middle of the linked list.RETURN: voidvoid Delete(Node* p){}1.3 Insert a new node before p WITHOUT using the HEAD pointerPARAM p: A pointer pointed to a node in the middle of the linked list.PARAM value: new Node valueRETURN: voidvoid Insert(Node* p, int value){}Question 2:Please write a String class with following features:

考题 若有以下定义则能保留链表其它结点,而删除p所指向结点的程序段是() A.head-next=p-next;free(p)B.head-next=p;p-next=head-next;free(p)C.free(p);head-next=p;p-next=head-nextD.free(p);head-next=p-next

考题 下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数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);}

考题 下而程序实现十进制向其他进制的转换。[C++程序]include"ioStream.h"include"math.h"include <conio.h>typedef struct node{int data;node *next;}Node;class Transform{public:void Trans(int d,int i); //d为数字;i为进制void print();private:Node *top;};void Transform.:Trans(int d,int i){int m,n=0;Node *P;while(d>0){(1) ;d=d/i;p=new Node;if(!n){P->data=m;(2) j(3) ;n++;}else{p->data=m;(4) ;(5) ;}}}void Transform.:print(){Node *P;while(top!=NULL){p=top;if(P->data>9)cout<<data+55:elsecout<<data;top=p->next;delete P;}}

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

考题 int AA(LNode *HL , ElemType x){int n=0; LNode *p=HL;while (p!=NULL){if (p->data= =x) n++;p=p->next; }return n;}对于结点类型为LNode的单链表,以上算法的功能为:()

考题 函数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;}

考题 设有指针head指向的带表头结点的单链表,现将指针p指向的结点插入表中,使之成为第一个结点,其操作是()(其中,p-next、head-next分别表示p、head所指结点的链域)。A、p-next=head-next;head-next=p;B、p-next=head-next;head=p;C、p-next=head;head=p;D、p-next=head;p=head;

考题 设有头指针为head的带有头结点的非空单向循环链表,指针p指向其尾结点,要删除头结点,并使其仍为单向循环链表,则可利用下述语句head =head-next ;()。A、p=head;B、p=NULL;C、p-next=head;D、head=p;

考题 已知head为带头结点的单循环链表的头指针,链表中的数据元素依次为(a1,a2,a3,a4,…,an),A为指向空的顺序表的指针。阅读以下程序段,并回答问题:(1)写出执行下列程序段后的顺序表A中的数据元素;(2)简要叙述该程序段的功能。if(head-next!=head){p=head-next;A-length=0;while(p-next!=head){p=p-next;A-data[A-length++]=p-data;if(p-next!=head)p=p-next;}}

考题 设有头指针为head的不带头结点的非空的单向循环链表,指针p指向其尾结点,要删除第一个结点,则可利用下述语句 head=head-next;和()。A、p=head;B、p=NULL;C、p-next=head;D、head=p;

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

考题 函数实现单链表的删除算法,请在空格处将算法补充完整。int ListDelete(LinkList L,int i,ElemType *s){ LNode *p,*q; int j; p=L;j=0; while(( (1) )(jnext;j++; } if(p-next==NULL||ji-1) return ERROR; q=p-next; (2) ; *s=q-data; free(q); return OK;}/*listDelete*/

考题 填空题函数实现单链表的删除算法,请在空格处将算法补充完整。int ListDelete(LinkList L,int i,ElemType *s){ LNode *p,*q; int j; p=L;j=0; while(( (1) )(jnext;j++; } if(p-next==NULL||ji-1) return ERROR; q=p-next; (2) ; *s=q-data; free(q); return OK;}/*listDelete*/

考题 问答题下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数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);}

考题 问答题已知head为带头结点的单循环链表的头指针,链表中的数据元素依次为(a1,a2,a3,a4,…,an),A为指向空的顺序表的指针。阅读以下程序段,并回答问题:(1)写出执行下列程序段后的顺序表A中的数据元素;(2)简要叙述该程序段的功能。if(head-next!=head){p=head-next;A-length=0;while(p-next!=head){p=p-next;A-data[A-length++]=p-data;if(p-next!=head)p=p-next;}}

考题 填空题写出算法的功能。int L(head){ node * head; int n=0; node *p; p=head; while(p!=NULL) { p=p-next; n++; } return(n); }