资源简介
很有价值的学习资源,老师给的优秀作品,值得我们学习。
代码片段和文件信息
#include “linklist.h“
#include
using namespace std;
linklist::linklist()
{
first = new Node();
}
linklist::linklist(int d)
{
first = new Node(d);
}
linklist::~linklist()
{
Empty();
}
void linklist::Empty()
{
Node *p;
while (first->rlink != first) {
p = first->rlink;
first->rlink = p->rlink;
delete p;
}
}
void linklist::Insert(int d)
{
Node *P *newnode = new Node(d);
P = first->rlink;
if (first->llink == NULL) {
first->llink = newnode;
first->rlink = newnode;
newnode->llink = first;
newnode->rlink = first;
}
else {
newnode->llink = first;
newnode->rlink = first->rlink;
P->llink = newnode;
first->rlink = newnode;
}
}
void linklist::Calculate(int n)
{
int total = 0 rem = 0;
Node *p = NULL;
Insert(1);
for (int i = 2; i <= n; i++) {
p = first->llink;
while (p != first) {
p->D = p->D*i + rem;
total = p->D;
if (total >= 1000) {
p->D = total % 1000;
rem = total / 1000;
}
else {
rem = 0;
}
p = p->llink;
}
if (rem != 0) {
Insert(rem);
rem = 0;
}
p = NULL;
}
cout << n << “的阶乘等于:“ << endl;
}
void linklist::Output()
{
Node *p = first->rlink;
cout << p->D;
p = p->rlink;
while (p != first) {
if (p->D >= 10 && p->D <= 99)
cout << 0 << p->D;
else if (p->D >= 0 && p->D <= 9)
cout << 0 << 0 << p->D;
else cout << p->D;
// cout << p->D;
p = p->rlink;
}
cout << endl;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 52224 2017-12-10 19:27 实习一-n(n≥20)的阶乘\Jiecheng.exe
文件 10616832 2017-12-10 19:32 实习一-n(n≥20)的阶乘\Jiecheng.sdf
文件 1306 2017-12-10 19:20 实习一-n(n≥20)的阶乘\Jiecheng.sln
文件 1489 2017-12-10 19:27 实习一-n(n≥20)的阶乘\li
文件 391 2017-12-10 19:24 实习一-n(n≥20)的阶乘\li
文件 243 2017-12-10 19:23 实习一-n(n≥20)的阶乘\Main.cpp
目录 0 2017-12-10 23:38 实习一-n(n≥20)的阶乘
----------- --------- ---------- ----- ----
10672485 7
评论
共有 条评论