stringnode.cpp

来自「异质链表 的实现 实现异质链表的查找、插入、删除和遍历」· C++ 代码 · 共 59 行

CPP
59
字号
// StringNode.cpp: implementation of the CStringNode class.
//
//////////////////////////////////////////////////////////////////////

#include "StringNode.h"
#include "string.h"
#include "iostream.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CStringNode::CStringNode(char* strvalue)
{
	m_strValue = new char[strlen(strvalue)+1];
	strcpy(m_strValue,strvalue);
}

CStringNode::CStringNode(const CStringNode& node)
{
	m_strValue = new char[strlen(node.m_strValue)+1];
	strcpy(m_strValue,node.m_strValue);
}

CStringNode::~CStringNode()
{
	delete[] m_strValue;
	m_strValue = 0;
}

void* CStringNode::Visit()
{
	cout << m_strValue << endl;
	return m_strValue;
}


CStringNode& CStringNode::operator= (const CStringNode& node)
{
	delete[] m_strValue;
	m_strValue = new char[strlen(node.m_strValue)+1];
	strcpy(m_strValue,node.m_strValue);
	return *this;
}

bool CStringNode::operator == (const CNodeBase* base)
{
	CNodeBase* pBase = const_cast<CNodeBase*>(base);
	CStringNode* pNode = dynamic_cast<CStringNode*>(pBase);
	if( pNode==0 )
		return false;
	if(strcmp(pNode->m_strValue,this->m_strValue)==0)
		return true;
	else
		return false;
/*	if( strcmp(m_strValue,node.m_strValue)==0 )
		return true;
	else
		return false;*/
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?