C++程序设计实践指导1.7超长数列中n个数排序改写要求实现
改写要求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个数排序改写要求实现的更多相关文章
- C++程序设计实践指导1.1删除序列中相同的数改写要求实现
改写要求1:改写为以指针为数据结构 #include <iostream> #include <cstdlib> using namespace std; class ARP ...
- C++程序设计实践指导1.5求两个整数集合并集改写要求实现
改写要求1:改写为单链表结构可以对任意长度整数集合求并集 #include <cstdlib> #include <iostream> using namespace std; ...
- C++程序设计实践指导1.2二维数组的操作运算改写要求实现
改写要求1:改写为以单链表表示二维数组 #include <cstdlib> #include <iostream> using namespace std; struct L ...
- C++程序设计实践指导1.4正整数转换为字符串改写要求实现
改写要求1:改为适合处理超长整数 #include <cstdlib> #include <iostream> #include <string> using na ...
- C++程序设计实践指导1.15找出回文数改写要求实现
改写要求1:用单链表实现 #include <cstdlib> #include <iostream> using namespace std; struct LinkNode ...
- C++程序设计实践指导1.14字符串交叉插入改写要求实现
改写要求:1:以指针为数据结构开辟存储空间 改写要求2:被插入字符串和插入字符串不等长,设计程序间隔插入 如被插入字符串长度为12,待插入字符串长度为5 则插入间隔为2 改写要求3:添加函数Inser ...
- C++程序设计实践指导1.13自然数集中找合数改写要求实现
改写要求1:用单链表实现 改写要求2:析构函数中依次将链表结点删除 #include <cstdlib> #include <iostream> using namespace ...
- C++程序设计实践指导1.12数组中数据线性变换改写要求实现
改写要求1:分别用指针pa.pb代替数组 改写要求2:从键盘输入data元素 元素个数任意,输入0结束 #include <cstdlib> #include <iostream&g ...
- C++程序设计实践指导1.10二维数组元素换位改写要求实现
改写要求1:改写为以单链表和双向链表存储二维数组 改写要求2:添加函数SingleLinkProcess()实现互换单链表中最大结点和头结点位置,最小结点和尾结点位置 改写要求3:添加函数Double ...
随机推荐
- java进程
package com.process; public class ProcessTest { public static void main(String[] args) { new Proce ...
- UIwebView的html字符串高度计算
) { webView = [[UIWebView alloc]initWithFrame:CGRectMake(, , DEVW-, webviewH)]; webView.delegate = s ...
- javascript 高级程序设计学习笔记(面向对象的程序设计) 1
Object构造函数或对象字面量都可以用来创建对象,但这些方式有个明显的缺点:使用相同一个接口创建很多对象,会产生大量重复代码. 工厂模式 //工厂模式 function createDog (nam ...
- (原)ubuntu上安装dlib
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5652791.html 参考网址: http://stackoverflow.com/questions ...
- (原)不明白JNI指针调用顺序
很不明白JNI里面获取指针的顺序(可能这样描述不太恰当吧). 下面按照传入指针的顺序的代码一跑就崩溃.如下: JNIEXPORT jint JNICALL Java_com_example_X_XX_ ...
- 学习PrintWriter类 .
java.io包 1)首先先知道它的八种构造方法,但怎么记住这八种呢?我们都知道PrintWriter是一种过滤流,也叫处理流.也就是能对字节流和字符流进行处理,所以它会有: PrintWriter( ...
- 第二章——第二节 IPC机制的概述和使用
一.Serialiable与Paracle ①.作用 ②.使用 二.Binder与AIDL ①.各自的作用 三.如何使用IPC机制 举例 四.IPC机制的原理 ①.流程图 ②.自己编译自动生成 ...
- POJ1094 拓扑排序
问题:POJ1094 本题考查拓扑排序算法 拓扑排序: 1)找到入度为0的点,加入已排序列表末尾: 2)删除该点,更新入度数组. 循环1)2)直到 1. 所有点都被删除,则找到一个拓扑 ...
- c++基础五个题(三)
一.一个对象访问普通函数和虚函数的时候,哪一个更快? 访问普通函数更快,因为普通成员函数在编译阶段已经被确定,因此在访问时直接调用对应地址的函数,而虚函数在调用时,需要首先在虚函数表中查找虚函数所在的 ...
- mysql--help不可用
1.问题描述: 执行help语句时没有得到相应的返回只是提示检查相关表是不是已经加载: mysql> help contents; Nothing found Please check if ' ...