改写要求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. Oracle CASE WHEN 用法介绍[Z]

    Oracle CASE WHEN 用法介绍 1. CASE WHEN 表达式有两种形式 --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ...

  2. 如何利用自己的电脑做服务器发布tomcat的WEB项目供外网访问

    1.首先你要确定你有一个外网ip地址.如果你分配到的是一个局域网IP地址需要经过一系列的转换为外网ip地址,然后继续下面操作. 2.拿到外网IP地址,进行tomcat的server.xml文件的配置. ...

  3. js 之 Post发送请求

    // ajax 对象 function ajaxObject() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp = new X ...

  4. CDZSC_2015寒假新人(1)——基础 i

    Description “Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you mus ...

  5. 指令中 controller && controllerAs

    1, controller 他会暴露一个API,利用这个API可以在多个指令之间通过依赖注入进行通信. controller($scope, $element, $attrs, $tranclude) ...

  6. css3 页面退出和进入的动画

    @-webkit-keyframes slideIn { from { -webkit-transform: translate3d(100%,0,0); transform: translate3d ...

  7. MySQL行级锁、表级锁、页级锁详细介绍

    原文链接:http://www.jb51.net/article/50047.htm 页级:引擎 BDB.表级:引擎 MyISAM , 理解为锁住整个表,可以同时读,写不行行级:引擎 INNODB , ...

  8. <Programming Collective Intelligence> Chapter2:Making Recommendations

    <Programming Collective Intelligence> Chapter2:Making Recommendations 欧几里得距离评价 皮尔逊相关度评价 它相比于欧几 ...

  9. [分享]我的LABVIEW快速开发串口测试软件实例

    LABVIEW是美国国家仪器公司(National Instruments,简称NI)的创新产品,它允许编程人员使用图形方式来进行编程,摒弃了艰涩难懂的代码,只需要拖动相应图形控件然后连线,进行简单的 ...

  10. 夏宇闻教授谈FPGA工程师的入门学习

    1. 必须清楚自己究竟适合不适合做工程师. 看看自己的性格特点,是不是特别安静,又耐得住寂寞.因为FPGA工程师是一个辛苦的工作,不但要通过不断学习研究提升自己的设计水平,还要经常性的熬夜加班敲写代码 ...