请写出下列递归算法的功能。  typedef struct node{          datatype data;

题目
问答题
请写出下列递归算法的功能。  typedef struct node{          datatype data;          struct node *link;  } *LinkList;  int ALGORISM(LinkList list)  {          if(list==NULL)              return 0;          else              return 1+ALGORISM(list->link);  }
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

设计递归算法,判断二叉树t是否满足小根堆的特点。二叉链表的类型定义如下:

typedef int datatype;        //结点的数据类型,假设为int

typedef struct NODE *pointer; //结点指针类型

struct NODE {

datatype data;

pointer lchild,rchild;

};

typedef pointer bitree;     //根指针类型


答案:   void moves(sqlist *L) {    int i,j; datatype x;    i=1;j=L->n;     while(i< j) {        while(L->data[i]< 0 && i< j) i++;        while(L->data[j]>=0 && i< j) j--;       if(i< j) {           x=L->data[i];L->data[i]=L->data[j];L->data[j]=x;           i++;j--;        }    } }

第2题:

以下程序把三 个 NODETYP E 型的变量链接成一个简单的链表 , 并 在 whil e 循环中输出链表结点数据域中的数据,请填空。

#include <stdio.h>

struct 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");

}


正确答案:

第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 结构变量


正确答案:C

第4题:

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


正确答案:

第5题:

阅读分析本题程序段后回答问题:(1)程序实现了什么功能?(2)写出程序的输出结果

阅读分析本题程序段后回答问题:

(1)程序实现了什么功能?(3分)

(2)写出程序的输出结果;(4分)

(3)写出算法的时间复杂度。(3分)

#include "stdio.h"

#define N 7

typedef int datatype;

void main(void)

{ int 1,j,t;

datatype data[N]={1,2,3, 4,5,6, 7}; /*处理的数据

*/

i=0;

j=N-1;

while (i<j)

{ t=data[i];

data[i++ ]=data[j];

data[j--]=t;

}

printf(”运行结果为: \n"); 

for(i= =0;i<N-1;i++)

printf("%d; ",data[i]);

}


答案:

(1)实现的功能:将数组里的数组逆序输出

(2)7;6;5;4;3;2

(3)时间复杂度为n

解析:

因为i<N-1,所以最后输出的结果中不会有1

第6题:

有以下程序段 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结构变量


正确答案:C

第7题:

以下程序把三个NODETYPE型的变量链接成一个简单的链表,并在while循环中输出链表结点数据域中的数据,请填空

#include <stdio.h>

struct 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】;}

}


正确答案:

15p=p—>next

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

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

#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

第10题:

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明]

完成以下中序线索化二叉树的算法。

[函数]

Typedef int datatype;

Typedef struct node {

Int ltag, rtag;

Datatype data;

*lchild,* rchild;

}bithptr;

bithptr pre;

void inthread ( p );

{if

{inthread ( p->lchild );

if ( p->lchild==unll ) (1);

if ( P->RCHILD=NULL) p->rtag=1;

if (2)

{if (3) pre->rchild=p;

if ( p->1tag==1 )(4);

}

INTHREAD ( P->RCHILD );

(5);

}

}


正确答案:(1) P->LTAG=0 (2) (PRE) (3) (PRE->RTAG==1) (4) P->LCHILD=PRE (5) PRE=P
(1) P->LTAG=0 (2) (PRE) (3) (PRE->RTAG==1) (4) P->LCHILD=PRE (5) PRE=P

更多相关问题