首页 > 编程语言 >C++ DoubleLinkedList

C++ DoubleLinkedList

时间:2022-10-30 17:12:51浏览次数:71  
标签:int list value order DoubleLinkedList C++ class

C++ DoubleLinkedList

For this assignment, create a class that represents a double linked list (forward and backward navigation), called DoubleLinkedList, of ints, that maintains a list in sorted order. The class should have the following operations:
DoubleLinkedList() : Appropriately initializes the object.
void insert(int value) : Inserts the value into the linked list, maintaining the sorted order.
void merge(DoubleLinkedList absorbedList) : Absorbs the provided list into the current list, maintaining sorted order. The absorbed list will be empty at the end of this operation.
void remove(int value) : removes an instance of the value provided from the list if it exists. If the value doesn't exist, the remove request takes no action. If the value is in the list more than once, only one instance needs to be removed.
const int& operator[](int index) const : Returns the value of the node in position index in the list. If the index is invalid, the operation throws an exception of type IndexOutOfBoundsException
. You may declare the exception class in the header file for DoubleLinkedList. Note: Overloading [] in this way provides read, but not write, access to the array in a natural way.
int getCount() const : returns the number of elements in the list
void display(int reverse = false) const : this operation displays the linked list in forward order if reverse is false and reverse order if reverse is true.
Your solution will be evaluated on the correctness of the header and implementation file. You are encouraged to also submit your main.cpp which should exemplify how you went about testing your class to ensure correctness.
You must build the class manually (do not use templates in your solution) and you must use any global data.

源码传送门

传送门:https://pan.baidu.com/s/1JJs9vbZahUCB6cQvXLgAVg?pwd=1111

标签:int,list,value,order,DoubleLinkedList,C++,class
From: https://www.cnblogs.com/codewriter/p/16841669.html

相关文章

  • C++——智能指针概述
    C++指针分类原始指针(rawpointer)智能指针:智能指针是原始指针的封装,其优点是会自动分配内存,不用担心潜在的内存泄露并不是所有的指针都可以封装成智能指针,很多时候......
  • 【C++】右值引用
    来源于:https://zhuanlan.zhihu.com/p/3359943701.什么是右值引用左值可以取地址、位于等号左边。右值没法取地址、位于等号右边。有地址的变量就是左值,没有地址的字面......
  • C++哈夫曼树
    C++哈夫曼树【讨论问题3】二叉树的应用—哈夫曼树[问题描述]在数据通信系统中,电文传送是经常遇到的问题,传送电文时需要将字符转换成二进制组成的字符串,当然在传送电文......
  • c++左值、右值、右值引用
    c++左值、右值、右值引用前言这一部分对于规范代码、提高安全性、加速调试等方方面面都很重要、、问就是天天在引用和const上报红;出现诸如''表达式必须是lvalue或xval......
  • C++模板的偏特化与全特化
    全特化的目的:当为特殊类型时,需要特殊处理。偏特化的目的:固定几个类型,其他类型不确定。函数模板是不允许偏特化的,但函数允许重载,从而声明另一个函数模板即可替代偏特化的需......
  • 实验3 数组、指针与现代C++标准库
    task1代码:1#include<iostream>23usingstd::cout;4usingstd::endl;56//绫籄鐨勫畾涔?7classA{8public:9A(intx0,inty0):x{x0}......
  • c++,真有趣啊
    由于笔者的水平不太行,在这个贴里记录一些自己犯过的不太容易被发现的错误20221029基类classCBase{public:virtual~CBase(){}private:virtualbool__......
  • C++11 unistring 类(编码转换)
    C++11 的编码转换程序: #ifndefUNISTRING_HPP#defineUNISTRING_HPP#include<algorithm>#include<codecvt>#include<cstdio>#include<cstdarg>#include<i......
  • C++ Primer Plus学习笔记之复合类型(上)
    前言个人觉得学习编程最有效的方法是阅读专业的书籍,通过阅读专业书籍可以构建更加系统化的知识体系。一直以来都很想深入学习一下C++,将其作为自己的主力开发语言。现在为......
  • C++求高精度pi(1)BBP公式
    C++求高精度pi(1)前言(之后再写)BBP公式由arctan1展开得到的莱布尼茨级数是一个交错级数,并且条件收敛而不绝对收敛,这注定了莱布尼兹级数方法会非常低效而BBP公式$$\sum......