有关腾讯校园招聘的笔试题目
1. 输入一个链表的头结点,从尾到头反过来输出每个结点的值。链表结点定义如下:
struct ListNode
{
int m_nKey;
ListNode* m_pNext;
};
A: 递归方法逆序输出,栈方法逆序输出。
(任意实现一种既可)
void PrintListUsingRecursicve(pListNode head)
{
if(head!=NULL)
{
PrintListUsingRecursicve(head->m_pNext);
printf("%d/n",head->m_nKey);
}
}
void PrintListUsingStack(pListNode head)
{
Stack s;
s.top=0;
pListNode p=head;
do{
push(&s,p->m_nKey);
p=p->m_pNext;
}while(p!=NULL);
while(!IsEmpty(&s))
{
printf("%d/n",pop(&s));
}
}
2. 二元树的深度
题目:输入一棵二元树的根结点,求该树的深度。从根结点到叶结点依次经过的结点(含根、叶结点)形成树的一条路径,最长路径的长度为树的深度。
#include
#include
#include
#include
#define MAXLEN 100
#define MAXNUM 10
typedef int Tree[MAXLEN];
Tree bt;
int GetDeep(int i)
{
int l=0,r=0;