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

题目内容 (请给出正确答案)
填空题
写出算法的功能。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)处的字句写在答题纸的对应栏内。【说明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;}}}}

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

考题 ●试题四阅读下列程序说明,将在空缺处填入正确的内容。【程序说明】定义一个多边形结构: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);}

考题 阅读以下说明和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的控制流程图。

考题 有以下程序: inClude structNODE{ int num; structNODE*next; }; main() {StructN00E 有以下程序:#inClude <stdlib.h>struct NODE{int num;struct NODE *next;};main(){ Struct N00E *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->num=1;q->num=2;r->num=3;p->next=q;q->next=r;r->next=NULL;sum+=q->next->num;sum+=p->num;printf("%d\n",sum);}执行后的输出结果是A.3B.4C.5D.6

考题 有以下程序: include include struct NODE {int num;struct NODE *next; } 有以下程序:#include <stdio.h>#include <stdlib.h>struct NODE{ int num;struct NODE *next;};main(){ struet NODE *p,*q,*r;int sum=0;p=(struct NODE *) malloc(sizeof(struct NODE));q=(struct NODE *) malloc(sizeof(struet NODE));r=(struct NODE *) malloc(sizeof(struct NODE));P- >num=1;q- >num=2;r->num=3;p- >next=q;q- >next=r;r- >next=NULL;sum + =q- >next- >num;sum + =P- >num;printf("%d\n",sum);}执行后的输出结果是( )A.3B.4C.5D.6

考题 阅读以下说明和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;}}}}

考题 试题五(共 15分)阅读以下关于 C语言及 C代码的叙述,回答问题 1至问题 3,将答案填入答题纸的对应栏内。【说明】在开发某嵌入式系统时,设计人员根据系统要求,分别编写了如下三部分程序,其中:【C代码 1】是李工为了在嵌入式平台上开发一段可变参数函数,在X86 平台上实现的一个参数个数可变函数实例。【C代码 2】是王工在编写软件时,自己编写的内存拷贝函数。【C代码 3】是赵工编写的一段数据处理的程序,其中 fun()的含义为从已创建的一个单向链表中查找倒数第index 个节点。他的设计思路为:首先创建两个指针 ptrl,ptr2,并且都指向链表头,然后 ptrl向前走index 步,这样ptrl和 ptr2 之间就间隔 index 个节点,然后 ptrl和ptr2 同时向前步进,当 ptrl到达最后一个节点时,ptr2 就是倒数第 index 个节点了。ReverseList()为赵工编写的对已有单向链表进行逆序重排的函数。【C代码 1】long sum(int i,...){int *p,j;long s = 0;p=i+1;for(j=0;ji;j++)s+=p[j]return s;}long Sum = sum(3,l,2,3);【C代码 2】static int pent;……void *MyMemcpy(void * dest, const void* src, int n ){char *pDest = (char *)dest;char *pSrc = (char *)src;for (int i=0;in; i++) {*(pDest +i) = *(pSrc+i);} return dest;}【C代码 3】node *fun(node * head, int index){node *ptr1,*ptr2;int 1 = 0;ptr1 = head;ptr2 = head;if( head == NULL || head-next == NULL)return ptrl;while(iindex){(1)if(ptrl == NULL)return head;i++;}while(ptrl-next != NULL){ptrl = ptrl-next;(2) ;}return (3) ;}node* ReverseList(node *head){node *templ = NULL;node *temp2 = NULL;node *temp3 = NULL;if((head-next == NULL) || (head == NULL)){return head;} templ=head;temp3= templ-next;templ-next= NULL;while(temp3-next!=NULL){temp2 = temp3;temp3= temp3-next;(4) ;templ=temp2;}temp3-next= templ;retum (5)}【问题1】(3分)执行【C代码 1】后,Sum的值应为多少?请用十进制表示。【问题2】(7分)请问【C代码2】中 static的作用是什么?const的作用是什么?王工自己编写的内存拷贝函数安全吗?如存在缺陷,请指出缺陷在哪里。【问题3】(5 分)仔细阅读并分析【C代码 3】,填补其中的空(1)~(5)。

考题 有以下程序 include struct NODE{ int num; struct NODE *next;}; main( ) 有以下程序#include <stdlib.h>struct NODE{int num;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->num=1;q->num=2;r->num=3;p->next=q;q->next=r;r->next=NULL;sum+=q->next->num;sum+=p->num;printf(“%d\n”,sum);}执行后的输出结果是A.3B.4C.5D.6

考题 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:

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

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

考题 有以下程序 inGlude struct NODE { int num; struct NODE *next; } main() {struct N 有以下程序#inGlude<stdlib.h>struct NODE {int num;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=(stnlct NODE*)malloc(sizeof(struct NODE));p->num=1;q->num=2;r->num=3;p->next=q;q->next;r;r->next=NULL;sum+=q->next->Num,sum+=p->num;printf("%d\n",sum);}执行后输出结果是A.3B.4C.5D.6

考题 下面程序的功能是建立一个有 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);}

考题 删除*(head-next)的操作是()A、p=head-next;head-next=head-next-next;delete p;B、head-next=head-next-next;p=head-next;delete p;C、p=head;head=head-next;delete p;D、head=head-next;p=head;delete 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;}}

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

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

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

考题 单选题删除*(head-next)的操作是()A p=head-next;head-next=head-next-next;delete p;B head-next=head-next-next;p=head-next;delete p;C p=head;head=head-next;delete p;D head=head-next;p=head;delete 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;} } }

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

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