#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
Node *next;
int data;
} *List;
void Init(List &l,int n)
{
Node *p,*current;
p=(List)malloc(sizeof(Node));
p->data=1;
p->next=NULL;
l=p;
current=p;
for(int i=2;i<=n;i++)
{
p=(List)malloc(sizeof(Node));
p->data=i;
p->next=NULL;
current->next=p;
current=p;
}
}
showList(List l)
{
while(l!=NULL)
{
printf("%d\t",l->data);
l=l->next;
}
}
List Find(List l,int num)
{
if(l==NULL)
{
return l;
}
else
{
if(l->data==num)
{
return l;
}
else
{
return Find(l->next,num);
}
}
}
void disPose(List &l)
{
Node *p;
p=l->next;
while(l!=NULL)
{
free(l);
l=p;
if(p!=NULL)
{
p=p->next;
}
}
}
int main()
{
List l,q;
Init(l,65145);
//showList(l);
q=Find(l,65145);//这个递归的最大深度就是64144
disPose(l);
return 0;
}
数据结构3.11答案 递归的查询单链表的其中的记录,以及最大能够让堆栈crash的值
最新推荐文章于 2022-03-23 19:29:00 发布