• 非递减单链表删除重复元素 转


        typedef struct _MyListNode  
        {  
            int nData;  
            struct _MyListNode * pNext;  
        } MyListNode, *PMyListNode;  
          
          
        class MyList  
        {  
        public:  
            MyList()  
            {  
                pHead = new MyListNode();  
                pHead->nData = 0;  
                pHead->pNext = NULL;  
                pTail = NULL;  
            }  
            ~MyList()  
            {  
                MyListNode * pTmp = pHead;  
                while (pTmp != NULL)  
                {  
                    pHead = pTmp->pNext;  
                    delete pTmp;  
                    pTmp = pHead;  
                }  
          
                pHead = NULL;  
            }  
          
            void Append(int num)  
            {  
                MyListNode * pTmp = new MyListNode();  
                pTmp->nData = num;  
                pTmp->pNext = NULL;  
          
                if (pTail != NULL)  
                {  
                    pTail->pNext = pTmp;  
                }  
                else  
                {  
                    pHead->pNext = pTmp;  
                }  
                pTail = pTmp;  
            }  
          
            void Print()  
            {  
                MyListNode * pTmp = pHead->pNext;  
                while (pTmp != NULL)  
                {  
                    cout << pTmp->nData << " ";  
                    pTmp = pTmp->pNext;  
                }  
                cout << endl;  
            }  
          
            void RemoveRepeat()  
            {  
                MyListNode * pNode = pHead->pNext;  
                while (pNode != NULL)  
                {  
                    MyListNode * pTmp = pNode->pNext;  
                    while (pTmp != NULL && pNode->nData == pTmp->nData)  
                    {  
                        pNode->pNext = pTmp->pNext;  
                        delete pTmp;  
                        pTmp = pNode->pNext;  
                    }  
          
                    pNode = pTmp;  
                }  
            }  
        private:  
            MyListNode * pHead;  
            MyListNode * pTail;  
          
        };  
          
          
        int main()  
        {  
            MyList lst;  
            lst.Append(7);  
            lst.Append(10);  
            lst.Append(10);  
            lst.Append(21);  
            lst.Append(30);  
            lst.Append(42);  
            lst.Append(42);  
            lst.Append(42);  
            lst.Append(51);  
            lst.Append(70);  
          
            lst.Print();  
          
            lst.RemoveRepeat();  
            lst.Print();  
          
            return 0;  
        } 

    http://blog.csdn.net/matrixcl/article/details/6853458

  • 相关阅读:
    set集合操作
    python中字符串操作
    字典----增删改查遍历
    C#反射回顾笔记
    消息队列之ActiveMQ学习笔记(二、C#实例实现)
    消息队列之ActiveMQ学习笔记(一、下载及安装)
    依赖注入之AutoFac
    layer弹框层学习笔记
    VS自定义代码块Code Snippet
    博客园添加链接
  • 原文地址:https://www.cnblogs.com/androllen/p/2843689.html
Copyright © 2020-2023  润新知