//Term.h
#pragma once
class Term
{
public:
Term();
int exp;
double coe;
Term(int exp, double coe);
};
//Term.cpp
#include"Term.h"
#include<iostream>
using namespace std;
Term::Term() {
exp = 0;
coe = 0.0;
}
Term::Term(int exp, double coe){
this->exp = exp;
this->coe = coe;
}
//Extended_queue.h
#pragma once
enum Error_code { success, overflow, underflow };
template<class Queue_entry>
class Extend_Queue
{
public:
Extend_Queue();
Extend_Queue(const Extend_Queue &original);
~Extend_Queue();
void operator=(const Extend_Queue & original);
Error_code append(const Queue_entry &item);
Error_code serve();
Error_code retriver(Queue_entry &item)const;
Error_code serve_and_retrieve(Queue_entry &item);
bool empty()const;
void clear();
int size();
protected:
struct Node
{
Node();
Node(Queue_entry item, Node *add_on = NULL);
Node *next;
Queue_entry entry;
};
int count;
Node *front;
Node *rear;
};
template<class Queue_entry>
inline Extend_Queue<Queue_entry>::Node::Node()
{
next = NULL;
}
template<class Queue_entry>
inline Extend_Queue<Queue_entry>::Node::Node(Queue_entry item, Node * add_on)
{
entry = item;
next = add_on;
}
//Extended_queue.cpp
#include<iostream>
#include"Extend_Queue.h"
using namespace std;
template<class Queue_entry>
Extend_Queue<Queue_entry>::Extend_Queue() {
count = 0;
Node *front = NULL;
Node *rear = NULL;
}
template<class Queue_entry>
Extend_Queue<Queue_entry>::Extend_Queue(const Extend_Queue & original)
{
Node *temp = original.front;
if (front == original.front)return;
while (temp) {
append(temp->entry);
temp = temp->next;
}
}
template<class Queue_entry>
Extend_Queue<Queue_entry>::~Extend_Queue()
{
clear();
}
template<class Queue_entry>
void Extend_Queue<Queue_entry>::operator=(const Extend_Queue & original){
Node *temp = original.front;
if (front == original.front)return;
while (temp) serve();
while (temp) {
append(temp->entry);
temp = temp->next;
}
}
template<class Queue_entry>
Error_code Extend_Queue<Queue_entry>::append(const Queue_entry & item)
{
if (count == 0) {
front = new Node(item);
rear = front;
count++;
return success;
}
else {
rear->next = new Node(item);
rear = rear->next;
count++;
return success;
}
}
template<class Queue_entry>
Error_code Extend_Queue<Queue_entry>::serve()
{
if (count == 0)return underflow;
if (count == 1) {
rear = NULL;
delete front;
front = NULL;
count--;
return success;
}
Node *temp = front;
front = front->next;
delete temp;
count--;
return success;
}
template<class Queue_entry>
Error_code Extend_Queue<Queue_entry>::retriver(Queue_entry & item) const
{
if (empty())return underflow;
item = front->entry;
return success;
}
template<class Queue_entry>
Error_code Extend_Queue<Queue_entry>::serve_and_retrieve(Queue_entry & item)
{
if (count == 0)return underflow;
retriver(item);
serve();
return success;
}
template<class Queue_entry>
bool Extend_Queue<Queue_entry>::empty() const
{
if (count == 0)return true;
else return false;
}
template<class Queue_entry>