改写要求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. (原)opencv直线拟合fitLine

    转载请注明出处 http://www.cnblogs.com/darkknightzh/p/5486234.html 参考网址: http://blog.csdn.net/thefutureisour ...

  2. 把EXCEL列号数字变成字母

    把Excel 列号数字变成字母 private static string ToName(int index) { if (index < 0) { throw new Exception(&q ...

  3. spring3+hibernate3+(dbcp+oracle+拦截器事务配置)整合(一)

    1.applicationContext-base.xml文件 <?xml version="1.0" encoding="UTF-8"?>< ...

  4. [C++程序设计]用函数指针变量调用函数

    指针变量也可以指向一个函数.一个函数在编译时被分配给一个入口地址.这个函数入口地址就称为函数的指针.可以用一个指针变量指向函数,然后通过该指针变量调用此函数 #include <iostream ...

  5. linux软件安装(rpm,源码编译)

    1.rpm(redhat package manager)管理器主要目的在于解决软件的安装.卸载.升级.查询.验证等,例如升级过程中,保留软件的配置文件,安装过程中,检查软件依赖的库文件,以及卸载过程 ...

  6. wordpress教程之如何修改与制作wordpress的作者页面

    一.如何使用与创建作者页面 一般情况下,多数主题下都有author.php这个文件,这既是作者展示页面.如果发现自己正在使用的主题中没有author.php这个文件的话, Wordpress 会默认寻 ...

  7. LeetCode_Jump Game II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典

    Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如 ...

  9. sqlexpress 不用管理工具 sa

    操作步骤: 开始=>运行=>(快捷键:win+R) cmd, 屎劲敲回车. 出现黑色的DOS窗体后,输入如下几条命令: 1.SQLCMD -S (local)\sqlexpress -E ...

  10. UESTC_传输数据 2015 UESTC Training for Graph Theory<Problem F>

    F - 传输数据 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...