⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dstype.h

📁 用列表实现的队列和栈的算法
💻 H
字号:
// Data Structure set ,general type difinition
// Written by Spirit [2002.10.24]
// Reversion history:
//----------------------------------------------

#ifndef _BASIC_DATA_STRUCTURE_TYPE_DEFINITION_
#define _BASIC_DATA_STRUCTURE_TYPE_DEFINITION_
#define _PROGRAMMING_WITH_C_PLUS_PLUS_ 
// The prefix 'sds' means 'Spirit Data Structure'
// The prefix 'sdstd' means 'Spirit Data Structure Type Definition'

// Following is the common type definition
#define SDS_OK      0
#define SDS_FAULT   1
#define SDS_CANCEL  2
#define SDS_RESULT  unsigned long
#define SDS_ERROR_BASE 200

//Following is the error No definition
#define SDS_ERROR_WRONG_SORT_MODE    12
#define SDS_ERROR_DELETING_NULL_ELEMENT    13
#define SDS_ERROR_WRONG_USHER_SUBSEQUENCE  14
#define SDS_ERROR_NOT_DELETE_LIST_HEAD_WHEN_USHER_NULL 15
#define SDS_ERROR_REQUIREMENT_OBJECT_NULL 16
#define SDS_ERROR_INVALID_PARAM           17
#define SDS_ERROR_BUFFER_FULL             18
#define SDS_ERROR_INPUT_PARAM_NULL        19

 




#ifndef NULL //define the pointer null
#define NULL 0x00
#endif


#define SDS_BOOL    int
#define SDS_TRUE    1
#define SDS_FALSE   0

#define SDS_STRING  char*     //the string type

#define SDS_KEYUP_SORT    1   // key up sort
#define SDS_KEYDOWN_SORT  2   // key down sort
#define SDS_KEYCONFUSION  0   // key is of confusion
#define SDS_SORTMODE      int // sort mode type
#define SDS_KEYTYPE       int

typedef char *sdstd_data;     //the general data type of this system
typedef sdstd_data sdstd_param;


struct sdstd_single_list_element{ // the single linked list element definition
sdstd_data data;
sdstd_single_list_element *next;
} ;
typedef sdstd_single_list_element *pssle; //point_sdstd_single_list_element


struct sdstd_double_list_element{ // the double linked list element definition
sdstd_data data;
sdstd_double_list_element *prev;
sdstd_double_list_element *next;
};
typedef struct sdstd_double_list_element *psdle; //point_sdstd_double_list_element


#define SDS_BASE_ERROR(errNo) ::sdstd_base_error_detail[errNo]
SDS_STRING sdstd_base_error_detail[SDS_ERROR_BASE+1]={
"Processing completed successfully!",//message 0
"Fatal Error!",//message 1
"Cancel Operation!",//message 2
"", //reserved area
"",
"",
"",
"",
"",
"",
"",
"",
"Wrong sort mode in mothod sdstd_single_list_impl::sortList(SDS_KEYTYPE (*getSortKey)(pssle pListElement),SDS_SORTMODE sortMode)!",
"Tring to Delete the NULL element in method 'sdstd_single_list::deleteElement(pssle pUsher,pssle pElement)', This is to say the input parameter pElement=NULL",
"The being deleted element not the subsequence of specific usher in method 'sdstd_single_list::deleteElement(pssle pUsher,pssle pElement)'.This is to say pUsher->next != pElement!",
"The usher is null,but the being deleted element not the head element of this list in method 'sdstd_single_list::deleteElement(pssle pUsher,pssle pElement)'.This is to say pUser=NULL,but pElement not point to first element of this list!",
"Your requirement meet a buffer null report!May be no more data in the buffer!",
"Input parameter is invalid.Maybe invalid or out of range!",
"The buffer is full,and cannot hold any more!",
"Your input parameter is NULL!"
"",
};//define the base error message




 
#if !(defined(_PROGRAMMING_WITH_C_PLUS_PLUS_) && defined(_PROGRAMMING_WITH_C_)) // both cannot be defined at the same time

#if defined(_PROGRAMMING_WITH_C_PLUS_PLUS_)// if C++ Language

#define SDSTD_INTERFACE    class   // the interface declaration
#define INTERFACE_METHOD virtual   // interface method decalaration



////////////////////////////////////////////////////////
//Single linked list
////////////////////////////////////////////////////////
SDSTD_INTERFACE sdstd_single_list // Abstract interface of single-linked list
{
public:

static pssle createElement(sdstd_data inData) // the list element creator
{
pssle pEle=new sdstd_single_list_element;
pEle->next=NULL;
pEle->data=inData;
return pEle;
}

static SDS_RESULT copyElement(pssle pTarget,pssle pSource) // the list element creator
{
	if(NULL==pTarget||NULL==pSource)
		return SDS_ERROR_INPUT_PARAM_NULL;
pTarget->data=pSource->data;

return SDS_OK;
}

static  SDS_STRING errorDetail(SDS_RESULT errorNo)//get the error detail description according to error number
{
 if(errorNo>SDS_ERROR_BASE) //if error number not in the range of this error expositor
	    return NULL;

 return SDS_BASE_ERROR(errorNo);
}

virtual ~sdstd_single_list(){
//just for dynamic deleting object and avoid memory leak
}

//INTERFACE_METHOD sdstd_single_list& operator=(sdstd_single_list inData)=0;

INTERFACE_METHOD SDS_RESULT copyList(const sdstd_single_list *pSource)=0; // copy thd source list to this list

INTERFACE_METHOD SDS_RESULT addHead(pssle inData)=0; // add an element before list head
INTERFACE_METHOD SDS_RESULT addTail(pssle inData)=0; // add an element after list tail

INTERFACE_METHOD SDS_RESULT getHead(pssle *pElement)const=0; // get the head element and store it to pElement buffer
INTERFACE_METHOD SDS_RESULT getTail(pssle *pElement)const=0; // get the tail element and store it to pElement buffer


INTERFACE_METHOD SDS_RESULT insertElement(pssle pUsher,pssle inData)=0; // add an element after the pUsher
INTERFACE_METHOD SDS_RESULT deleteElement(pssle pUsher,pssle pElement)=0; // deleting the element


INTERFACE_METHOD SDS_RESULT traverseInit()=0; //Initialization for list traverse
INTERFACE_METHOD SDS_BOOL   hasNext()const=0;      // detecting whether list contains more element
INTERFACE_METHOD SDS_RESULT getNext(pssle *pElement)=0; // get the element and store it to pElement buffer

INTERFACE_METHOD SDS_BOOL   isEmpty() const=0;

INTERFACE_METHOD SDS_RESULT sortList(SDS_KEYTYPE (*getSortKey)(pssle pListElement),SDS_SORTMODE sortMode)=0; // sorting this list with the specifed mode <key-up or key-down>
INTERFACE_METHOD SDS_RESULT traverseThrough(SDS_RESULT (*elementProcessor)(pssle pListElement,sdstd_param inParam,sdstd_param outParam),sdstd_param inParam=(sdstd_param)0,sdstd_param outParam=(sdstd_param)0)=0; //traverse the list with specifed processor

INTERFACE_METHOD SDS_RESULT reverseList()=0; // reverse the list 

INTERFACE_METHOD SDS_STRING (*getErrorExpositor())(SDS_RESULT errorNo)=0; // get the error number expositor

INTERFACE_METHOD SDS_RESULT setSequence(SDS_SORTMODE sortMode)=0; //Set the list to obey a mode of sequence
};




////////////////////////////////////////////////////////
//Queue 
////////////////////////////////////////////////////////
SDSTD_INTERFACE sdstd_queue // Abstract interface of queue
{
public:
virtual ~sdstd_queue(){
//just for dynamic deleting object and avoid memory leak
}

INTERFACE_METHOD SDS_RESULT inQueue(sdstd_data inData)=0; // get data into queue
INTERFACE_METHOD SDS_RESULT outQueue(sdstd_data *outData)=0; // get data out of queue
INTERFACE_METHOD SDS_RESULT peekQueue(sdstd_data *outData)=0; // peek the data which will be outQueue next time,but not get the data out of the queue

INTERFACE_METHOD SDS_RESULT setSize(int queueSize)=0; // set the size of the queue

INTERFACE_METHOD SDS_BOOL   isEmpty() const=0;// test whether the queue is null or not

};

////////////////////////////////////////////////////////
//Stack
////////////////////////////////////////////////////////
SDSTD_INTERFACE sdstd_stack // Abstract interface of queue
{
public:
virtual ~sdstd_stack(){
//just for dynamic deleting object and avoid memory leak
}

INTERFACE_METHOD SDS_RESULT push(sdstd_data inData)=0; // push data to stack
INTERFACE_METHOD SDS_RESULT pop(sdstd_data *outData)=0; //pop the data
INTERFACE_METHOD SDS_RESULT peek(sdstd_data *outData)=0; // peek the data which will be pop next time,but not get the data out of the stack
INTERFACE_METHOD SDS_RESULT setSize(int stackSize)=0; // set the size of the stack
INTERFACE_METHOD SDS_BOOL   isEmpty() const=0;// test whether the stack is null or not

};





#elif defined(_PROGRAMMING_WITH_C_) // if C Language
     

     


#else // if define nothing,error
        
//you do NOT define programming language // just for causing error!

#endif

#endif

#endif  

⌨️ 快捷键说明

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