[数据结构]Polynomial

//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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值