题目描述:
Implement the class with given header.
As you guess, DouList means 逗list, very funny.
to_str() function means displaying the list with std::string, formating like [1, 2, 3, 4] , [2] or [] (empty list)(notice white-space)
operator<< means output the string from ‘to_str()’
struct DouListNode is the node of DouList.
if you have any doubt in function of the member methods, take a look at STL.
中文描述概要:
0 大概是让你实现一个双头列表。
1 如果对成员函数的作用有疑问,参照STL的常规含义。
2 to_str()就是把list输出成标准字符串的形式。operator<<则打印to_str()得到的字符串。
测试文件:
//created by my TA
#include <iostream>
#include "DouList.h"
using namespace std;
DouList list1, list2;
void display() {
cout << list1.empty() << ':' << list1 << endl;
cout << list2.empty() << ':' << list2.to_str() << endl;
}
int main() {
display();
list1.push_front(894);
list2.push_back(2136);
cout << list1.front() << ',' << list1.back() << endl;
cout << list2.front() << ',' << list2.back() << endl;
display();
list1.push_back(214);
list2.push_front(931);
cout << list1.front() << ',' << list1.back() << endl;
cout << list2.front() << ',' << list2.back() << endl;
display();
for (int i = 0; i < 10; ++i) {
int t;
cin >> t;
list1.push_back(t);
list2.push_front(t);
}
display();
for (int i = 0; i < 5; ++i) {
list1.p