字符串的拷贝、二叉树的拷贝

char* strcpy(char* strDest,const char* strSrc)
{
    assert((strDest != NULL)&&(strSrc != NULL));
    char* adress=strDest;//记录strDest的首位置
    while(strSrc !='\0')
    {
        *strDest++=*strSrc++;//不是strDest++=strSrc++
    }
    return adress;//返回strDest的首位置
}

#define IS_FULL(ptr) (!(ptr))
node* treecpy(node* original)
{
    if(original==NULL)
    {
        return NULL;
    }else{
    node* newNode=(node*)malloc(sizeof(node));
    if(IS_FULL(newNode)){
    printf("The memory is full.\n");
    exit(1);
    }
    newNode->data=original->data;
    newNode->left=treecpy(original->left);
    newNode->right=treecpy(original->right);
    return newNode;
    }
}
posted @ 2012-04-11 14:48  logzh  阅读(320)  评论(0编辑  收藏  举报