循环链表按条件分割_C++实现
来源:互联网 发布:刹车片 知乎 编辑:程序博客网 时间:2024/06/05 06:20
构造一个循环链表
存放一个含有三种字符(数字,字母,其他)字符序列
不开辟新空间
将该链表分割成三个循环链表
每个存放一种字符
"head.h"
#include<iostream>#include<ctype.h>#define DIGIT 1#define ALPHA 2#define OTHER 3using namespace std;class NODE{public:char atom;int flag;NODE *next;};class DATA{public:DATA();void Constructor();void PrePrint();void Process();void Print();private:NODE * head,*head1,*head2,*head3,*p,*p1,*p2,*p3;};DATA::DATA(){head=head1=head2=head3=p=p1=p2=p3=NULL;}void DATA::Constructor(){cout<<"Constructor Called !"<<endl<<endl;bool hasinput=false;char input;while(cin>>input){if(!hasinput){head=new NODE;head->atom=input;if(isdigit(input))head->flag=DIGIT;else if(isalpha(input))head->flag=ALPHA;elsehead->flag=OTHER;p=head;hasinput=true;}else{p->next=new NODE;p=p->next;p->atom=input;if(isdigit(input))p->flag=DIGIT;else if(isalpha(input))p->flag=ALPHA;elsep->flag=OTHER;}}if(!hasinput){cout<<"No Data Input !"<<endl<<endl;}else{p->next=head;}}void DATA::PrePrint(){cout<<"PrePrint Called !"<<endl<<endl;if(head==NULL){cout<<"No Data !"<<endl<<endl;return;}p=head;cout<<p->atom<<endl;p=p->next;while(p!=head){cout<<p->atom<<endl;p=p->next;}cout<<endl;}void DATA::Print(){cout<<"Print Called !"<<endl<<endl;if(head1==NULL){cout<<"No Data !"<<endl<<endl;}else{p1=head1;cout<<p1->atom<<endl;p1=p1->next;while(p1!=head1){cout<<p1->atom<<endl;p1=p1->next;}cout<<endl<<endl;}if(head2==NULL){cout<<"No Data !"<<endl<<endl;}else{p2=head2;cout<<p2->atom<<endl;p2=p2->next;while(p2!=head2){cout<<p2->atom<<endl;p2=p2->next;}cout<<endl<<endl;}if(head3==NULL){cout<<"No Data !"<<endl<<endl;}else{p3=head3;cout<<p3->atom<<endl;p3=p3->next;while(p3!=head3){cout<<p3->atom<<endl;p3=p3->next;}cout<<endl<<endl;}}void DATA::Process(){cout<<"Process Called !"<<endl<<endl;if(head==NULL){cout<<"No Data !"<<endl<<endl;return;}p1=head1;p2=head2;p3=head3;p=head;while(1){if(p->flag==DIGIT){if(p1==NULL){head1=p;p1=head1;}else{p1->next=p;p1=p1->next;}}else if(p->flag==ALPHA){if(p2==NULL){head2=p;p2=head2;}else{p2->next=p;p2=p2->next;}}else{if(p3==NULL){head3=p;p3=head3;}else{p3->next=p;p3=p3->next;}}p=p->next;if(p==head){if(p1!=head1)p1->next=head1;if(p2!=head2)p2->next=head2;if(p3!=head3)p3->next=head3;return;}}}
"main.cpp"
#include<iostream>#include"head.h"using namespace std;int main(){DATA data;data.Constructor();data.PrePrint();data.Process();data.Print();system("pause");}
- 循环链表按条件分割_C++实现
- 黑马程序员_C语言循环
- 循环条件
- 条件,循环
- 循环&条件
- 堆排序实现_c++
- 插入排序实现_c++
- 快速排序实现_c++
- 归并排序实现_c++
- 快速排序实现_c++
- 二叉排序树_C++实现
- R_条件分割图
- for循环,循环条件
- 例-存储过程实现循环插入数据&&字符分割
- C语言互斥锁-双条件变量实现循环打印
- 剑指offer---不使用循环条件判断等实现求和
- JSP C标签实现<c:forEach> 满足条件跳出循环
- 用循环打印菱形_C语言算法
- Matlab实现——Adaptive Quadrature Using Simpson’s Rule
- JDBC简介
- 软件工程二(1):可行性研究报告样本
- 2011-09-13
- 再网页中添加搜索引擎
- 循环链表按条件分割_C++实现
- 从汇编简要分析c语言函数调用栈
- 信息化基础知识
- WScript.SendKeys
- 我喜欢现在的生活
- Matlab实现——Differentiation Using Limits
- 关于online judge系统
- 经典十五课
- 深入理解 C++ 指针(三)---运算符&和*