main.cpp
#include <iostream>
#include "queue.h"
using namespace std;
int main()
{
using namespace work;
Queue<int> q;
Queue<int> p;
Queue<int> w;
char ch;
int select=0;
char *m = new char [1000];
cout<<"欢迎来到大数据的四则运算:>"<<endl;
cin.getline(m,1000);
GetNumber(ch,m,&q,&p);
// MOD_POWER(&q,&p,&w);
// w.view();
switch(ch)
{
case '+':
ADD_S(&q,&p,&w);
w.view();
break;
case '-':
DEC_S(&q,&p,&w);
w.view();
break;
case '*':
MUL_S(&q,&p,&w);
w.view();
break;
case '/':
{
cout<<"1进入整数运算,2进入小数运算:"<<endl;
cin>>select;
if(select==2)
{
DIV_R(&q,&p,&w);
w.view();
}
else
{
DIV_S(&q,&p,&w);
w.view();
}
}
break;
case '%':
MOD(&q,&p,&w);
w.view();
break;
case '^':
POWER_S(&q,&p,&w);
w.view();
break;
case '@':
MOD_POWER(&q,&p,&w);
w.view();
default:
break;
}
return 0;
}
queue.h:
#pragma once
#include <iostream>
using namespace std;
namespace work
{
template<typename T>
class Queue;
template<typename T>
void ADD(Queue<T> *q,Queue<T> *p,Queue<T> *m);
template<typename T>
void DEC(Queue<T> *q,Queue<T> *p,Queue<T> *m);
template<typename T>
void DIV(Queue<T> *list1,Queue<T> *list2,Queue<T> *list3);
enum WHAT
{
Plus,
Minus,
};//确定符号位。
template<typename T>
class DList
{
friend class Queue<T>;
private:
int data;//数据域
DList *prev;
DList *next;
};
template<typename T>
class Queue
{
private:
DList<T> *head;
DList<T> *tail;
int size;//链表长度。
int Split;//小数点位数。
public:
Queue()
{
head = tail = new DList<T>();
tail -> next = NULL;
head -> prev = NULL;
size = 0;
Split = 0;
}
void Set_Split(int x)
{
Split = x;//设置小数点位数
}
int COMPLATE_SPLIT(const Queue<T> *list)
{
if(Split > list->Split)
{
return 1;
}
else if(Split == list->Split)
{
return 0;
}
else
{
return -1;
}
}//比较小数点位数
int Get_Split()
{
return Split;
}//得到小数点位数
void Head_val(int x)
{
head->data = x;
}//设置头节点的值(所谓的符号位)
int Tail_Return()
{
return tail->data;
}//返回尾节点值
int Head_Return()
{
return head->data;
}//返回头节点的值,也就是符号位。
Queue(const Queue &q)
{
head = tail =new DList<T>();
tail -> next = NULL;
head ->prev = NULL;
size = 0;
DList<T> *p = (q.head)->next;
while(p!=NULL)
{
this->push_back(p->data);
p=p->next;
}
}
Queue operator = (const Queue &q)
{
head = tail = new DList<T>();
tail -> next =NULL;
head -> prev = NULL;
size = 0;
DList<T> *p = (q.head)->next;
while(p!=NULL)
{
this->push_back(p->data);
p = p->next;
}
}
bool IS_empy()
{
return ((size>0));
}
int SIZE()
{
return size;
}
void CLEAR()
{
DList<T> *p = head->next;
tail = head;
tail -> next = NULL;
head ->prev = NULL;
while(p != NULL)
{
DList<T> *q = p->next;
delete p;
p = q;
}
}
int Get_Number()
{
int temp = 0;
Queue<T> mylist = *this;
for(int i = this->SIZE();i>0;--i)
{
temp = temp*10 + this->PopHead();
}
*this = mylist;
return temp;
}//将链表转化为数字。
void POW(int x)
{
Queue<T> list1;
Queue<T> list2;
Queue<T> list3;
Queue<T> list4 = *this;
for(int i=0;i<x;i++)
{
ADD(this,&list1,&list2);
list3 = list2;
list1.CLEAR();
list2.CLEAR();
list1 = list3;
*this = list4;
}
this->CLEAR();
*this = list3;
}//list*[1-9]。
int PopTail()
{
if(size==0)
{
return 0;
}
else
{
int x = tail->data;
DList<T> *p = tail->prev;
delete tail;
tail = p;
tail->next = NULL;
size--;
return x;
}
}
int PopHead()
{
if(size == 0)
{
return 0;
}
else
{
T x = head->next->data;
DList<T> *p = head->next;
if ( p->next != NULL )