Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!

image text in transcribed

image text in transcribed

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

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

When may an item of OCI be recycled through net income?

Answered: 1 week ago