• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

这是一个用单链表写的大数阶乘,求各位帮忙看一下这个代码哪里不对,为什么

#include "stdafx.h"#includeusing namespace std;templateclass Link;//链表类 templateclass LinkNode{        friend Link;private:        T data;        LinkNode*link;};templateclass Link{public:Link()        {                first = 0;        };~Link();          bool IsEmpty()const          {      return first = 0;           }        int Length()const;        bool Find(int k, T&x);        Link&Insert(int k, const T&x);        Link&Change(int k, T x);        Link&Delete(int k, T &x);        Link&Search(const T&x)const;        int OutPut();private:        LinkNode*first;};//析构函数(删除链表的所有节点)templateLink::~Link(){        LinkNode*next;        while (first)        {                next = first->link;                delete first;                first = next;        }}//确定链表的长度templateint Link::Length()const{        LinkNode*current = first;        int len = 0;        while (current)        {                len++;                current = current->link;        }        return len;}//在链表中查找第K个元素templatebool Link::Find(int k, T &x){        LinkNode*current = first;        int index = 0;        while (index < k&&current)        {                current = current->link;                index++;        }        if (current)        {        int x = current->data;        return true;    }        return false;}//向链表中插入元素templateLink&Link::Insert(int k, const T&x){        LinkNode*p = first;        for (int index = 1; index < k&&p; index++)                p = p->link;        LinkNode*y = new LinkNode;        y->data = x;        if (k)        {                y->link = p->link;                p->link = y;        }        else         {                y->link = first;                first = y;        }        return *this;}        //改变链表第k个元素的值    template        Link&Link::Change(int k, T x)        {                LinkNode*p = first;                for (int index = 0; p&&index < k; index++)                 {                        p = p->link;                }                if (p)                        p->data = x;                return *this;        }        //删除链表第k个元素        template        Link&Link::Delete(int k, T&x)        {                if (k = 0)                {                        first = first->link;                }                else                        LinkNode*p= first;                LinkNode*q = first;                for (int index = 1; index < k - 1 && q; index++)                {                        q = q->link;                        p = q->link;                        q->link = p->link;                        x = p->data;                        delete p;                        return *this;                }        }        //搜索第k个元素        template        Link&Link::Search(const T&x)const{                LinkNode*current = first;                int index = 1;                while (current&&current->data != x)                {                        current = current->link;                        index++;                }                if (current)                        return index;                                        return 0;    }        //倒序输出链表        template        int Link::OutPut()        {                LinkNode*current = first;                int index = 0;                int len = 0;                while (current)                {                        len++;                        current = current->link;                }        int *arry = new int[len];        current = first;        while (current)        {                arry[index] = current->data;                current = current->link;                index++;}        index = index - 1;        cout = 0; index--)        {                cout.fill('0');                cout.width(3);                cout

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!