改写要求1:将以上程序改写为适合超长整数

改写要求2:将以上程序改写为适合超长数列

改写要求3:将数列中指定位置m开始的n个结点重新按降序排序

改写要求4:输出指定位置m开始的n个结点的超长整数

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
struct LongIntegerNode
{
short int data;
LongIntegerNode *next;
}; struct LinkNode
{
LongIntegerNode *pLongIntegerNode;
LinkNode *next;
};
class LIST
{
public:
struct LongIntegerNode* creat(string str);
struct LinkNode* add(LinkNode* Head,LongIntegerNode* pHead);
struct LinkNode* sortpart(LinkNode* Head,int m,int n);
void output(LinkNode* Head)
{
LinkNode* p;
p=Head->next;
LongIntegerNode* q;
while(p)
{
q=p->pLongIntegerNode->next;
while(q)
{
cout<<q->data;
q=q->next;
}
cout<<endl;
p=p->next;
}
}
void show(LinkNode* Head,int n)
{
LinkNode* p;
p=Head;
LongIntegerNode* q;
while(n)
{
q=p->pLongIntegerNode->next;
while(q)
{
cout<<q->data;
q=q->next;
}
cout<<endl;
p=p->next;
n--;
}
} }; LinkNode* LIST::add(LinkNode* node,LongIntegerNode* pHead)
{
LinkNode* newLinkNode=new LinkNode;
newLinkNode->next=NULL;
newLinkNode->pLongIntegerNode=pHead;
node->next=newLinkNode;
node=newLinkNode;
return node;
} LongIntegerNode* LIST::creat(string str)
{
string s=str.substr(,);
int i=;
LongIntegerNode* pHead=new LongIntegerNode;
pHead->next=NULL;
LongIntegerNode* p;
p=pHead;
while(s.length())
{
LongIntegerNode* newLongIntegerNode=new LongIntegerNode;
newLongIntegerNode->next=NULL;
newLongIntegerNode->data=atoi(s.c_str());
p->next=newLongIntegerNode;
p=newLongIntegerNode;
if(s.length()<)
return pHead;
s=str.substr(i,);
i=i+;
}
return pHead;
} LinkNode* LIST::sortpart(LinkNode* Head,int m,int n)
{
int x=m;
int y=n;
int temp;
LinkNode* p=Head->next;
LinkNode* q;
LongIntegerNode* t,*s;
while(x)
{
p=p->next;
x--;
}
q=p;
while(y)
{
for(t=p->pLongIntegerNode;t!=NULL;t=t->next)
{
for(s=t->next;s!=NULL;s=s->next)
{ if(t->data<s->data)
{
temp=t->data;
t->data=s->data;
s->data=temp; }
}
} p=p->next;
y--;
}
return q;
} int main(int argc, char *argv[])
{
LIST list;
LinkNode* Head=new LinkNode;
Head->next=NULL;
LinkNode* sort;
LinkNode* tail;
tail=Head;
string str;
cin>>str;
while(str!="exit")
{
LongIntegerNode* pHead;
pHead=list.creat(str); tail=list.add(tail,pHead);
cin>>str;
}
sort=list.sortpart(Head,,);
list.output(Head);
cout<<"输出指定的排序数列"<<endl;
list.show(sort,);
system("PAUSE");
return EXIT_SUCCESS;
}

C++程序设计实践指导1.7超长数列中n个数排序改写要求实现的更多相关文章

  1. C++程序设计实践指导1.1删除序列中相同的数改写要求实现

    改写要求1:改写为以指针为数据结构 #include <iostream> #include <cstdlib> using namespace std; class ARP ...

  2. C++程序设计实践指导1.5求两个整数集合并集改写要求实现

    改写要求1:改写为单链表结构可以对任意长度整数集合求并集 #include <cstdlib> #include <iostream> using namespace std; ...

  3. C++程序设计实践指导1.2二维数组的操作运算改写要求实现

    改写要求1:改写为以单链表表示二维数组 #include <cstdlib> #include <iostream> using namespace std; struct L ...

  4. C++程序设计实践指导1.4正整数转换为字符串改写要求实现

    改写要求1:改为适合处理超长整数 #include <cstdlib> #include <iostream> #include <string> using na ...

  5. C++程序设计实践指导1.15找出回文数改写要求实现

    改写要求1:用单链表实现 #include <cstdlib> #include <iostream> using namespace std; struct LinkNode ...

  6. C++程序设计实践指导1.14字符串交叉插入改写要求实现

    改写要求:1:以指针为数据结构开辟存储空间 改写要求2:被插入字符串和插入字符串不等长,设计程序间隔插入 如被插入字符串长度为12,待插入字符串长度为5 则插入间隔为2 改写要求3:添加函数Inser ...

  7. C++程序设计实践指导1.13自然数集中找合数改写要求实现

    改写要求1:用单链表实现 改写要求2:析构函数中依次将链表结点删除 #include <cstdlib> #include <iostream> using namespace ...

  8. C++程序设计实践指导1.12数组中数据线性变换改写要求实现

    改写要求1:分别用指针pa.pb代替数组 改写要求2:从键盘输入data元素 元素个数任意,输入0结束 #include <cstdlib> #include <iostream&g ...

  9. C++程序设计实践指导1.10二维数组元素换位改写要求实现

    改写要求1:改写为以单链表和双向链表存储二维数组 改写要求2:添加函数SingleLinkProcess()实现互换单链表中最大结点和头结点位置,最小结点和尾结点位置 改写要求3:添加函数Double ...

随机推荐

  1. SqlServer日期查询

    一.sql server日期时间函数 Sql Server中的日期与时间函数 1.  当前系统日期.时间 select getdate() 2. dateadd  在向指定日期加上一段时间的基础上,返 ...

  2. (原)Ubuntu16中编译caffe

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5797526.html 参考网址: http://caffe.berkeleyvision.org/in ...

  3. 从汇编看c++中的placement operator new

    placement operator new是重载的operator new运算符,它允许我们将对象放到一个指定的内存中.下面来看c++源码: class X { private: int _x; p ...

  4. NopCommerce 3.3中文语言包发布下载及使用

    NopCommerce 3.3是一套国外优秀的开源电子商务项目,其拥有完整的电子商务功能且具有灵活的配置功能,基于微软最新技术ASP.NET MVC 5.1.1,EntityFramework.6.1 ...

  5. 正确看待HTML5的语法变化

    也许会有人问:“HTML4已经很普及了,如果改变基础语法,会不会有什么影响?” 我们都知道,在HMTL5之前几乎没有符合标准规范的Webu浏览器!在这种情况下,各个浏览器之间的互相兼容性和互操作性在很 ...

  6. Sunscreen(POJ 3614 优先队列)

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5898   Accepted: 2068 Descrip ...

  7. HDU 1026 Ignatius and the Princess I(BFS+优先队列)

    Ignatius and the Princess I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  8. iOS开发多线程-多线程技术1

    一.基本概念 1.什么是进程 进程就是指在系统中正在运行的一个应用程序 每个应用之间是相互独立的 每个进程都运行在其专有的并且受保护的内存空间内. 2.什么是线程 一个进程想要执行程序,就必须需要一个 ...

  9. SD/MMC卡初始化及读写流程

    二.MMC/SD卡的模型和工作原理 PIN脚.SD卡总线.SD卡结构.SD卡寄存器.上电过程 SD卡寄存器:  OCR:操作电压寄存器: 只读,32位 第31位: 表示卡上电的状态位   CID: 卡 ...

  10. 苹果开发证书相关BLOG与Delphi IOS环境安装(超详细)

    注:有好的资源,请添加了上传,上传后,通知管理员,删除旧文件,累积相关的学习资源,方便新手学习 一.相关论坛http://www.2ccc.com/ delphi 合子 www.2pascal.com ...