实现一颗二叉树的层序遍历
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;
}