1、利用原来的存储空间实现单链表的就地逆置
voidresverse(LinkList&L){p=L->next;//L为单链表的头结点L->next=null;while(p){q=p;p=p->next;q->next=L->next;L->next=q;}}2、编写计算数组元素累加和的递归函数templateTRsum(Ta[],intn){//计算a[0:n-1]的和if(n>0)returnRsum(a,n-1)+a[n-1];return0;}3、编程实现在带头结点的head单链表的结点a之后插入新元素x
classnode{public:elemtypedata;node*next;};voidlkinsert(node*head,elemtypex){node*s,*p;s=newnode;s->data=x;p=head->next;while(p
=NULL)&&(p->data
=a)p=p->next;if(p==NULL)coutnext;p->next=s;1}}4、在栈顶指针为HS的链栈中编写计算该链栈中结点个数的函数
intcount(node*HS){node*p;intn=0;p=HS;while(p
=NULL){n++;p=p->next;}return(n);}5、给定二叉树的两种遍历序列,分别是:前序遍历序列:ABECDFGHIJ;中序遍历序列:EBCDAFHIGJ,试画出二叉树
当前序序列为ABECDFGHIJ,中序序列为EBCDAFHIGJ时,逐步形成二叉树的过程如下图所示:6、编写递归算法,计算二叉树中叶子结点的数目
intNumOfLeaves(Node*t)const{if(t==NULL)return0;elseif(t->left==Null&&t->right==Null)return1;elsereturnNum