Click here to Skip to main content
15,880,427 members
Articles / Programming Languages / Visual C++ 10.0

SIP Stack (1 of 3)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
20 Aug 2012CPOL3 min read 30K   1.7K   4  
SIP Stack Implementation on the basis of RFC SIP 3261 Specification
#pragma once

#ifndef CSortedBinaryTree_h
	#define CSortedBinaryTree_h

	#include "ASyncronizationClass.h"
	#include "FWCoreDLLImportExportDeclaration.h"

	namespace CoreFW
	{
		template< typename ClassType >
		class DLL_TEMPLATE_DECLARATION_SPECIFIER CBinaryTreeNode
		{
		public:
			CBinaryTreeNode() ;
			CBinaryTreeNode( ClassType *pDataObject ) ;

			virtual ~CBinaryTreeNode() ;

		public:
			ClassType		*m_pDataObject ;
			CBinaryTreeNode		*m_pLeftChildNode ;
			CBinaryTreeNode		*m_pRightChildNode ;
		} ;


		template< typename ClassType >
		class CPreOrderBinaryTreeIterator ;

		template< typename ClassType >
		class CInOrderBinaryTreeIterator ;

		template< typename ClassType >
		class CPostOrderBinaryTreeIterator ;

		template< typename ClassType >
		class DLL_TEMPLATE_DECLARATION_SPECIFIER CSortedBinaryTree
		{
			friend class CPreOrderBinaryTreeIterator<ClassType> ;
			friend class CInOrderBinaryTreeIterator<ClassType> ;
			friend class CPostOrderBinaryTreeIterator<ClassType> ;

		public:
			CSortedBinaryTree() ;
			virtual ~CSortedBinaryTree() ;

			bool Insert( ClassType *pDataObject ) ;
			void Print() ;
			int Size() ;
			bool IsEmpty() ;
			bool Find( ClassType *pDataObject ) ;
			ClassType* Minimum() ;
			ClassType* Maximum() ;
			bool Remove( ClassType *pDataObject ) ;
			void RemoveAll() ;

		private:
			CBinaryTreeNode<ClassType>* CreateNode( ClassType *pDataObject ) ;
			bool InsertNode( CBinaryTreeNode<ClassType> **ppSubTreeRootNode,
											CBinaryTreeNode<ClassType> *pNewBinaryTreeNode ) ;
			void PreOrderPrint( CBinaryTreeNode<ClassType> *pSubTreeRootNode ) ;
			void PostOrderPrint( CBinaryTreeNode<ClassType> *pSubTreeRootNode ) ;
			void InOrderPrint( CBinaryTreeNode<ClassType> *pSubTreeRootNode ) ;
			int GetSize( CBinaryTreeNode<ClassType> *pSubTreeRootNode ) ;
			bool IsEmpty( CBinaryTreeNode<ClassType> *pSubTreeRootNode ) ;
			CBinaryTreeNode<ClassType>* FindNode( CBinaryTreeNode<ClassType> *pSubTreeRootNode, 
														CBinaryTreeNode<ClassType> *pSubTreeParentNode, 
														ClassType *pDataObject,
														CBinaryTreeNode<ClassType> **ppBTParentNode ) ;
			CBinaryTreeNode<ClassType>* MinimumNode( CBinaryTreeNode<ClassType> *pSubTreeRootNode,
														CBinaryTreeNode<ClassType> *pSubTreeParentNode, 
														CBinaryTreeNode<ClassType> **ppBTParentNode ) ;
			CBinaryTreeNode<ClassType>* MaximumNode( CBinaryTreeNode<ClassType> *pSubTreeRootNode,
														CBinaryTreeNode<ClassType> *pSubTreeParentNode, 
														CBinaryTreeNode<ClassType> **ppBTParentNode ) ;
			bool DeleteNode( ClassType *pDataObject ) ;
			bool RemoveNodeLink( CBinaryTreeNode<ClassType> *pBTNodeToDelete,
															   CBinaryTreeNode<ClassType> *pBTParentNode ) ;

		private:
			CBinaryTreeNode<ClassType>		*m_pRootNode ;
			ASyncronizationClass *m_pBinaryTreeSyncObject ;
		} ;
	
	} // End Namespace

	#if defined( DLL_TEMPLATE_DECLARATION_SPECIFIER_EXPORT )
		#include "CSortedBinaryTree.cpp"
	#endif	

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Hatim Haidry

VC++, Technical Architect

India

haidryhatim@gmail.com

Comments and Discussions