データ構造の単一チェーンテーブル実現キューC++


#ifndef STL_SDFLSJ_H
#define STL_SDFLSJ_H

/************************************************************************/
/*        C++
/************************************************************************/

/************************************************************************/
/*    
/************************************************************************/
//    
template 
class CNode
{
public:
	Elemplent data;
	CNode *next;
public:
	CNode ();
	CNode(Elemplent tempElemplent,CNode* tempNext = NULL); 
	~CNode();
};

//      
template
CNode::CNode()
{
	next = NULL;
}

//      
template
CNode::~CNode()
{

}

//       
template
CNode::CNode(Elemplent tempElemplent,CNode* tempNext )
{
	data = tempElemplent;
	next = tempNext;
}

/************************************************************************/
/*        
/************************************************************************/

template
class ListSequence
{
protected:
	CNode *front,*rear;
	int CountTotal;
public:
	ListSequence();
	~ListSequence();
	ListSequence(const ListSequence& tempptr);
	ListSequence& operator = (const ListSequence& tempptr);
	void InitListSequence();
public:
	bool IsEmpty();
	void Clear();
	int GetLength()const;
	bool Insert(const Elemplent & tempElemplent);
	bool Delete();
}

template
ListSequence::ListSequence()
{
	InitListSequence();
}
template
ListSequence::~ListSequence()
{
	delete front;
};
template 
void ListSequence::Clear()
{
	while(IsEmpty()!)
	{
		Delete();
	}
};

template 
void ListSequence::InitListSequence()
{
	front = new CNode;
	rear = front;
	CountTotal = 0;
}

template 
int ListSequence::GetLength()
{
	return CountTotal;
}

template 
bool ListSequence::IsEmpty()
{
	return front == rear;
}
template 
bool ListSequence::Delete()
{
	if (IsEmpty())
	{
		return false;
	}
	CNode *temptr = front->next;
	front->next = temptr->next;
	delete temptr;
	CountTotal--;
	return true;
}
template 

template 
bool ListSequence::Insert(const Elemplent & tempElemplent)
{
	CNode *newptr = new CNode(tempElemplent,NULL);
	rear->next = newptr;
	CountTotal++;
	return true;
}

template
ListSequence::ListSequence(const ListSequence& tempptr)
{
	if (tempptr.IsEmpty())
	{
		return *this;
	}
	InitListSequence();
	CNode * tempcopy = tempptr.front;
	CNode * tempGet;
	for (tempcopy->next;tempcopy!=NULL;tempcopy = tempcopy->next )
	{
		tempGet =new CNode;
		tempGet->data = tempcopy->data;
		Insert(tempGet);
	}
	return *this;
}
template
ListSequence& ListSequence::operator=(const ListSequence& tempptr)
{
	if (tempptr.IsEmpty())
	{
		return *this;
	}
	if (this == tempptr)
	{
		return *this;
	}
	Clear();
	InitListSequence();
	CNode * tempcopy = tempptr.front;
	CNode * tempGet;
	for (tempcopy->next;tempcopy!=NULL;tempcopy = tempcopy->next )
	{
		tempGet =new CNode;
		tempGet->data = tempcopy->data;
		Insert(tempGet);
	}
	return *this;
}


#endif