Question: Hello all, need some help with a homework problem below, anything helps! linked_list.h: #include node.h #include #include class LinkedList{ private: Node* head; unsigned int size;

Hello all, need some help with a homework problem below, anything helps!

Hello all, need some help with a homework problem below, anything helps!

linked_list.h: #include "node.h" #include #include class LinkedList{ private: Node* head; unsigned int

linked_list.h:

#include "node.h" #include #include

class LinkedList{ private: Node* head; unsigned int size;

public: LinkedList(); // this->head = nullptr; LinkedList(int data); LinkedList(std::vector vec); ~LinkedList();

void push_front(int data); void push_back(int data); void insert(int data, int idx); // For any `idx` > `size`, append the value void remove(int data); bool contains(int data); int get_size(); std::string to_string(); };

linked_list.cpp:

#include "linked_list.h" #include

LinkedList::LinkedList(){

}

LinkedList::LinkedList(int data){

}

LinkedList::LinkedList(std::vector vec){

}

LinkedList::~LinkedList(){

}

void LinkedList::push_front(int data){

}

void LinkedList::push_back(int data){

}

void LinkedList::insert(int data, int idx){

}

void LinkedList::remove(int data){

}

bool LinkedList::contains(int data){

}

int LinkedList::get_size(){ return this->size; }

// O(n) std::string LinkedList::to_string(){ std::string stringified; Node* tmp = this->head;

while(tmp != nullptr){ stringified += std::to_string(tmp->data) + " "; tmp = tmp->next; }

return stringified; }

node.h:

#pragma once

// head // 5 -> 3 -> 8 -> 6 -> X // p1

class Node{ private: int data; Node* next;

friend class LinkedList; public: Node(); // Overloading Node(int data); Node(int data, Node* next); ~Node(); };

node.cpp:

#include "node.h"

// Default constructor Node::Node(){ this->data = 0; this->next = nullptr; }

Node::Node(int data){ this->data = data; this->next = nullptr; }

Node::Node(int data, Node* next){ this->data = data; this->next = next; }

Node::~Node(){ if(this->next != nullptr){ delete this->next; } }

main.cpp:

#include "linked_list.h" #include #include #include #include

int main(int argc, char* argv[]){

}

The following structure needs to be followed. If you need more information please let me know. Thanks in advance

Your task is to create both a LinkedList class that utilizes a Node class that stores integers, and performs the following tasks: - push_front - Adds an integer to the front of the list - push_back - Adds an integer to the end of the list - insert - Adds an integer to the list at a specific index - delete - Searches for \& removes a specific element in the list - contains - Returns true if the given value exists in the list. False otherwise. - size - Returns the \# of elements in the list - to_string - Returns all elements in the list concatenated into a single string. The list 5342 would return "5 342 " You should submit the following files: - linked-list.h - linked-list.cpp - node.hp node.cpp - main.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!