一个简单的双向链表的例子

题目描述: 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 [] (emp
摘要由CSDN通过智能技术生成

题目描述:
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值