和通过代码相比仅仅是函数名和变量名不一样,为什么报错?

剑指offer的在线编程题:
复杂链表的复制:输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)
/* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : label(x), next(NULL), random(NULL) { } }; */ class Solution { public: void CloneNode(RandomListNode* pHead){ RandomListNode* pNode = pHead; while (pNode != NULL){ RandomListNode* pTemp = new RandomListNode(0); pTemp->lable = pNode->lable; pTemp->next = pNode->next; pTemp->random = NULL; pNode->next = pTemp; pNode = pTemp->next; } } void RandomListNode(RandomListNode* pHead){ RandomListNode* pNode = pHead; while (pNode != NULL){ RandomListNode* pTemp = pNode->next; if (pNode->random != NULL){ pTemp->random = pNode->random->next; } pNode = pTemp->next; } } RandomListNode* SingleClone(RandomListNode* pHead){ RandomList* pNode = pHead; RandomList* pCloneHead = NULL; RandomList* pCloneNode = NULL; if (pNode != NULL){ pCloneHead = pCloneNode = pNode->next; pNode->next = pCloneNode->next; pNode = pNode->nxet; } while (pNode != NULL){ pCloneNode->next = pNode->next; pCloneNode = pCloneNode->next; pNode->next = pCloneNode->next; pNode = pNode->next; } return pCloneHead; } RandomListNode* Clone(RandomListNode* pHead) { CloneNode(pHead); RandomListNode(pHead); return SingleClone(pHead); } };
---------------------
报错:
编译错误:您提交的代码无法完成编译
In file included from 第2行:
./solution.h:37:2: error: must use 'struct' tag to refer to type 'RandomListNode' in this scope
RandomListNode* SingleClone(RandomListNode* pHead){
^
struct
./solution.h:25:7: note: struct 'RandomListNode' is hidden by a non-type declaration of 'RandomListNode' here
void RandomListNode(RandomListNode* pHead){
^
./solution.h:37:30: error: must use 'struct' tag to refer to type 'RandomListNode' in this scope
RandomListNode* SingleClone(RandomListNode* pHead){
^
struct
./solution.h:25:7: note: struct 'RandomListNode' is hidden by a non-type declaration of 'RandomListNode' here
void RandomListNode(RandomListNode* pHead){
^
./solution.h:54:2: error: must use 'struct' tag to refer to type 'RandomListNode' in this scope
RandomListNode* Clone(RandomListNode* pHead)
^
struct
./solution.h:25:7: note: struct 'RandomLi
----------------------------------------------------------
然后查看了通过代码:
classSolution {
public:
    //复制原始链表的任一节点N并创建新节点N',再把N'链接到N的后边
    voidCloneNodes(RandomListNode* pHead)
    {
        RandomListNode* pNode=pHead;
        while(pNode!=NULL)
        {
            RandomListNode* pCloned=newRandomListNode(0);
            pCloned->label=pNode->label;
            pCloned->next=pNode->next;
            pCloned->random=NULL;
              
            pNode->next=pCloned;
              
            pNode=pCloned->next;
        }
    }
    //如果原始链表上的节点N的random指向S,则对应的复制节点N'的random指向S的下一个节点S'
    voidConnectRandomNodes(RandomListNode* pHead)
    {
        RandomListNode* pNode=pHead;
        while(pNode!=NULL)
        {
            RandomListNode* pCloned=pNode->next;
            if(pNode->random!=NULL)
                pCloned->random=pNode->random->next;
            pNode=pCloned->next;
        }
    }
    //把得到的链表拆成两个链表,奇数位置上的结点组成原始链表,偶数位置上的结点组成复制出来的链表
    RandomListNode* ReConnectNodes(RandomListNode* pHead)
    {
        RandomListNode* pNode=pHead;
        RandomListNode* pClonedHead=NULL;
        RandomListNode* pClonedNode=NULL;
          
        //初始化
        if(pNode!=NULL)
        {
            pClonedHead=pClonedNode=pNode->next;
            pNode->next=pClonedNode->next;
            pNode=pNode->next;
              
        }
        //循环
        while(pNode!=NULL)
        {
            pClonedNode->next=pNode->next;
            pClonedNode=pClonedNode->next;
            pNode->next=pClonedNode->next;
            pNode=pNode->next;
        }
          
        returnpClonedHead;
          
    }
    //三步合一
    RandomListNode* Clone(RandomListNode* pHead)
    {
        CloneNodes(pHead);
        ConnectRandomNodes(pHead);
        returnReConnectNodes(pHead);
    }
};

--------------------
但是我想问,到底和我的有什么区别啊?仅仅是函数名和变量名不一样,为什么我的就报错,他的就通过?百思不得其解,顺便请问我上面的编辑报错,是闹哪样?求高手解答~

全部评论
同学你太不细心啦,17行的label写错了,42行的next写错了 这个函数名和结构体重复了。。
点赞 回复 分享
发布于 2017-04-01 13:27

相关推荐

去B座二楼砸水泥地:不过也可以理解,这种应该没参加过秋招
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务