面试题目搜集(5)
本博客的《面试题目搜集系列不错》
(1)面试题目搜集1
(2)面试题目搜集2
(3)面试题目搜集3
(4)面试题目搜集4
(5)面试题目搜集5
1.递归打印链表
class CString{public:CString(const char *pStr = NULL){if(pStr == NULL){pData = new char;*pData = '\0';}else{pData = new char[strlen(pStr)+1];assert(pData != NULL);strcpy(pData,pStr);}}CString(const CString& other){pData = new char[strlen(other.pData)];assert(pData != NULL);strcpy(pData,other.pData);}CString& operator=(const CString& other){if(&other == this){CString strTemp(other);char *pTemp = strTemp.pData;strTemp.pData = pData;pData = pTemp;}return *this;}~CString(){if(!pData)delete[] pData;}private:char *pData;};