mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 22:28:40 +08:00 
			
		
		
		
	fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. (#423)
This commit is contained in:
		@ -92,6 +92,7 @@ public:
 | 
			
		||||
            if (fNext != nullptr) {
 | 
			
		||||
                fNext->prev = nullptr;
 | 
			
		||||
                front->next = nullptr;
 | 
			
		||||
                delete front;
 | 
			
		||||
            }
 | 
			
		||||
            front = fNext;   // 更新头结点
 | 
			
		||||
        // 队尾出队操作
 | 
			
		||||
@ -102,6 +103,7 @@ public:
 | 
			
		||||
            if (rPrev != nullptr) {
 | 
			
		||||
                rPrev->next = nullptr;
 | 
			
		||||
                rear->prev = nullptr;
 | 
			
		||||
                delete rear;
 | 
			
		||||
            }
 | 
			
		||||
            rear = rPrev;    // 更新尾结点
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user