实现一颗二叉树的层序遍历
typedef struct Node
{
int val;
struct Node* left;
struct Node* right;
Node(const int& data)
:val(data)
, left(NULL)
, right(NULL)
{}
}Node;
template<class T>
void ThiefOrder(Node* root)
{
if (root == NULL)
return;
Node* cur = root;
queue<Node*> q;
q.push(cur);
while (cur)
{
Node* front = q.front();
cout << front->val << endl;
if (front->left != NULL)
{
q.push(front->left);
}
if (front->right != NULL)
{
q.push(front->right);
}
q.pop();
}
}
给定一个整数N,那么N的阶乘N!末尾有多少个0呢?例如:N=10,N!=3 628 800,N!的末尾有两个0
#include<iostream>
using namespace std;
int main()
{
int num = 0;
int n = 0;
printf("please input n:");
scanf("%d", &n);
while (n)
{
num += n / 5;
n = n / 5;
}
cout << num << endl;
system("pause");
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)