#pragma once
#include <utility>
#include <iostream>
template <typename T>
class Deque{
struct Data{
Data* next;
Data* previous;
T info;
};
public:
Deque(){
this->right = nullptr;
this->left = nullptr;
}
void push_back(T element){
Data* ref = new Data{
nullptr,
right,
std::move(element)
};
if(this->left == nullptr && this->right == nullptr){
this->left == ref;
}else{
this->right->next = ref;
}
this->right = ref;
}
T pop_back(){
T t = std::move(this->right->info);
Data* ref = this->right;
this->right = this->right->previous;
this->right->next = nullptr;
delete ref;
return t;
}
private:
Data* left;
Data* right;
};
为什么push_back
方法中不满足条件:
if(this->left == nullptr && this->right == nullptr)
一开始,当我将第一个元素添加到容器中时,字段left
和被right
初始化为nullptr
. 但条件仍然失败。
这就是原因
编译器只是跳过这一行
应该写