Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) Implement a doubly linked list. Please write simple tests for all functions. Keep track of your edge cases: empty, 1 item, 2+ items You

(C++) Implement a doubly linked list.

Please write simple tests for all functions.

Keep track of your edge cases: empty, 1 item, 2+ items You need to update 3 nodes every time you insert or remove: the previous node, the selected node, and the next node.

node.h file

#ifndef LABS_NODE_H #define LABS_NODE_H

namespace lab0{ class node{ int data; public: node* next; node* prev; explicit node(int input_data) : data(input_data), next(nullptr), prev(nullptr){}; int get_data(){return data;}; }; }

#endif

header file

#ifndef DOUBLY_LINKED_LIST_H #define LABS_DOUBLY_LINKED_LIST_H #include "node.h" #include #include

namespace lab0{ class doubly_linked_list{ lab0::node *head; lab0::node *tail; public: doubly_linked_list(); doubly_linked_list(int input); doubly_linked_list(std::vector vector_input); doubly_linked_list(const doubly_linked_list &original); ~doubly_linked_list(); int get_data(unsigned position); std:vector get_set(unsigned position_from, unsigned position_to); unsigned size(); bool is_empty(); void append(int input); void insert(int input, unsigned location = 0); void remove(unsigned location); doubly_linked_list split(unsigned position); doubly_linked_list split_set(unsigned position_1, unsigned position_2); void swap(unsigned position_1, unsigned position_2); void swap_set(unsigned location_1_start, unsigned location_1_end, unsigned location_2_start, unsigned location_2_end); void sort(); doubly_linked_list operator+(const doubly_linked_list &rhs) const; doubly_linked_list& operator=(const doubly_linked_list &rhs); doubly_linked_list& operator+=(const doubly_linked_list &rhs); bool operator==(const doubly_linked_list &rhs); friend std::ostream& operator<<(std::ostream& stream, doubly_linked_list& RHS); friend std::istream& operator>>(std::istream& stream, doubly_linked_list& RHS); }; } #endif //DOUBLY_LINKED_LIST_H

cpp file #include "doubly_linked_list.h" namespace lab0{

doubly_linked_list::doubly_linked_list() { }

doubly_linked_list::doubly_linked_list(int input) { } doubly_linked_list::doubly_linked_list(std::vector vector_input) { } doubly_linked_list::doubly_linked_list(const doubly_linked_list &original) { } doubly_linked_list::~doubly_linked_list() { }

int doubly_linked_list::get_data(unsigned position) { }

std::vector doubly_linked_list::get_set(unsigned position_from, unsigned position_to) { }

unsigned doubly_linked_list::size() { }

bool doubly_linked_list::is_empty() { }

void doubly_linked_list::append(int input) { }

//This inserts a node *at* the location provided. Note that if you don't give it a location to insert the node, it will insert it at the beginning of the linked_list. void doubly_linked_list::insert(int input, unsigned int location) { }

void doubly_linked_list::remove(unsigned location) { }

//Split the doubly linked list at position, with position being the head of the second linked list. Truncate the original linked list and return the split off linked list. doubly_linked_list doubly_linked_list::split(unsigned position) { }

doubly_linked_list doubly_linked_list::split_set(unsigned position_1, unsigned position_2) { }

//Swap the node located at position 1 with the node located at position 2. void doubly_linked_list::swap(unsigned position_1, unsigned position_2) { }

//Swap the subset of nodes starting at position_1_start and ending at position_1_end with the nodes starting at position_2_start to position_2_end. These locations are **inclusive.** void doubly_linked_list::swap_set(unsigned location_1_start, unsigned location_1_end, unsigned location_2_start, unsigned location_2_end) { }

//will sort the items in a linked list using insertion sort. //Don't move **data** in the node from *private* to *public*. We placed this here deliberately. For all of the functions and classes, don't change anything. void doubly_linked_list::sort() { }

//Append the right doubly linked list to the right doubly linked list and return that new doubly linked list object. doubly_linked_list doubly_linked_list::operator+(const doubly_linked_list &rhs) const { }

//Copy the right doubly linked list into left doubly linked list doubly_linked_list& doubly_linked_list::operator=(const doubly_linked_list &rhs) { }

//Append an entire doubly linked list to the end of an existing doubly linked list doubly_linked_list& doubly_linked_list::operator+=(const doubly_linked_list &rhs) { }

//Checks to see if two doubly linked lists have the same values in the same positions. bool doubly_linked_list::operator==(const doubly_linked_list &rhs) { }

std::ostream &operator<<(std::ostream &stream, doubly_linked_list &RHS) { }

std::istream &operator>>(std::istream &stream, doubly_linked_list &RHS) { } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions