Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ ONLY PLEASE. My question is below: May I get help to create the LinkedList.h file? =====Pickle.h===== #ifndef PICKLE_H #define PICKLE_H class Pickle { private:

C++ ONLY PLEASE.

My question is below:

May I get help to create the LinkedList.h file?

image text in transcribedimage text in transcribed

image text in transcribed

=====Pickle.h=====

#ifndef PICKLE_H

#define PICKLE_H

class Pickle

{

private:

string type;

bool bumpySkin;

bool sweet;

public:

//CONSTRUCTORS

Pickle(){}

Pickle(string t, bool b, bool swe)

{

this->type = t;

this->bumpySkin = b;

this->sweet = swe;

}

//OVERLOADED

friend ostream & operator

{

os

os

if(p.bumpySkin)

os

else

os

os

if(p.sweet)

os

else

os

return os;

}

//OVERLOADED relational operators to be able to search for a specific pickle object by type

bool operator !=(const Pickle& p)

{

if(this->type != p.type)

return true;

else

return false;

}

//OVERLOADED == OPERATOR to be able to search for a specific pickle object by type

bool operator ==(const Pickle& p)

{

if(this->type == p.type)

return true;

else

return false;

}

};

#endif

=================================================================================

=========LinkedList.h=========

#ifndef LinkedList_H

#define LinkedList_H

#include

using namespace std;

template

class LinkedList

{

private:

struct ListNode

{

//STRUCTURE MEMBERS NEED TO BE ADDED HERE

};

ListNode *head;

ListNode *tail;

public:

LinkedList()

{

head = NULL;

tail = NULL;

}

~LinkedList();

void appendNode(T value);

void deleteNode(int position);

void displayList() const;

};

//DEFINE ALL OTHER LinkedList class FUNCTIONS BELOW THIS LINE--------------------------------

#endif

================================================================================

======Driver.cpp=======

#include

#include //for the toupper function

#include //to use numeric_limits

#include "LinkedList.h"

#include "Pickle.h"

using namespace std;

void printPickle();

int main()

{

LinkedList list;

int num;

char response;

//Print some cute pickle art

printPickle();

cout

cin.get();

//ADD SOME PICKLES

cout

Pickle pickle1("Bread-and-butter", false, true);

list.appendNode(pickle1);

Pickle pickle2("Gherkin", true, true);

list.appendNode(pickle2);

Pickle pickle3("Kosher Dill", true, false);

list.appendNode(pickle3);

Pickle pickle4("Hungarian", false, false);

list.appendNode(pickle4);

Pickle pickle5("Lime", false, false);

list.appendNode(pickle5);

cout

list.displayList();

cout

cin >> num;

//input validation loop

while(!cin || num 5) //!cin tests if the input good bit (ios::good) is not true

{

cin.clear(); //sets ios::good back to true and all other bits back to false

/*

The ignore below will remove all leftover characters or numbers

from keyboard buffer to start with fresh input.

Also, you must #include to use numeric_limits

*/

cin.ignore(numeric_limits::max(),' ');

cout

cin >> num;

}

list.deleteNode(num-1);

cout

cin >> response;

//input validation loop

while(!cin || toupper(response) != 'Y' && toupper(response) != 'N')

{

cin.clear();

cin.ignore(numeric_limits::max(),' ');

cout

cin >> response;

}

if(toupper(response) == 'Y')

{

cout

list.displayList();

}

cout

cin.get();

cout

cout

return 0;

}

/*

Function: printPickle()

Purpose: print a cute pickle in ASCII art to the screen

*/

void printPickle()

{

}

Show transcribed image text

Expert Answer

  • Know Everything With MG answered this

    Was this answer helpful?

    1

    0

    93 answers

    As you only requested for linkedlist.h, I have completed it.

    #ifndef LinkedList_H #define LinkedList_H #include  using namespace std; template class LinkedList { private: struct ListNode { //STRUCTURE MEMBERS NEED TO BE ADDED HERE T data; ListNode *next; }; ListNode *head; ListNode *tail; public: LinkedList() { head = NULL; tail = NULL; } ~LinkedList(); void appendNode(T value); void deleteNode(int position); void displayList() const; }; //DEFINE ALL OTHER LinkedList class FUNCTIONS BELOW THIS LINE-------------------------------- template void LinkedList::appendNode(T value) { ListNode *node = new ListNode(); node->data = value; node->next = NULL; if(head == NULL) { head = node; tail = head; }else { tail->next = node; tail = tail->next; } } template LinkedList::~LinkedList() { ListNode* curr = head; while(curr != NULL) { ListNode *next = curr->next; cout  void LinkedList::deleteNode(int position) { if(head == NULL) return; ListNode *curr = head; ListNode *prev = NULL; while(curr != NULL && position-- > 0) { prev = curr; curr = curr->next; } if(curr == NULL) return; cout next = curr->next; delete curr; } template void LinkedList::displayList() const { if(head == NULL) { cout data next; } } } #endif
5:46 Quill 53% 3. Implement the linked list template class in LinkedList.h. The class declaration is written for you except for entering the correct structure members. You will need to implement all the public member functions except for the constructor, which is already implemented as an inline member function. o appendNode function accept the template data type as a parameter dyn ally allocate a new ListNode and set the ListNode's value to the value sent to this function place the new node at the end of the linked list (use the tail pointer to help!) deleteNode function accept an integer position which indicates which node should be deleted. Position zero is the first node. 0 If the linked list is empty, stop this function from running If the position sent to this function is zero, delete the head node and make sure to print out "-----DELETING the node with address: " and then print the node's memory address. 5:46 PM till 53% function is zero, delete the head node and make sure to print out----DELETING the node with address: " and then print the node's memory address. Otherwise, traverse the linked list to search for a node at the given position (if it exists) and delete it. Make sure to print out "-----DELETING the node with address: and then print the node's memory address that you are deleting. displayList function If there are no nodes in the list, just print out that there are no nodes in the list. Otherwise, traverse the linked list and print out each node EXACTLY like the sample output (given below)! Destructor O 0 Delete all nodes that remain in the linked list Before deleting the node, make sure to print out ******DELETING the node with address: " and then print the node's memory address that you are Press enter to continue ! Adding some pickles to the linked list! Now printing out the pickles: -- Node 1 with memory address Oxb47ee8 Pickle Type: Bread-and-butter Bumpy Skin? no Sweet? yes ----- Node 2 with memory address Oxb40590 Pickle Type: Gherkin Bumpy Skin? yes Sweet? yes ----- Node 3 with memory address Oxb41610 Pickle Type: Kosher Dill Bumpy Skin? yes Sweet? no -----Node 4 with memory address Oxb41638 Pickle Type: Hungarian Bumpy Skin? no Sweet? no ---Node 5 with memory address oxb41660 Pickle Type: Lime Bumpy Skin? no Sweet? no Which pickle do you want to eat (and therefore remove from the list)? Choose the node number (1-5): 1 -----DELETING the node with address: Oxb47ee8 Would you like to display the list of pickles again? (y) 5:46 Quill 53% 3. Implement the linked list template class in LinkedList.h. The class declaration is written for you except for entering the correct structure members. You will need to implement all the public member functions except for the constructor, which is already implemented as an inline member function. o appendNode function accept the template data type as a parameter dyn ally allocate a new ListNode and set the ListNode's value to the value sent to this function place the new node at the end of the linked list (use the tail pointer to help!) deleteNode function accept an integer position which indicates which node should be deleted. Position zero is the first node. 0 If the linked list is empty, stop this function from running If the position sent to this function is zero, delete the head node and make sure to print out "-----DELETING the node with address: " and then print the node's memory address. 5:46 PM till 53% function is zero, delete the head node and make sure to print out----DELETING the node with address: " and then print the node's memory address. Otherwise, traverse the linked list to search for a node at the given position (if it exists) and delete it. Make sure to print out "-----DELETING the node with address: and then print the node's memory address that you are deleting. displayList function If there are no nodes in the list, just print out that there are no nodes in the list. Otherwise, traverse the linked list and print out each node EXACTLY like the sample output (given below)! Destructor O 0 Delete all nodes that remain in the linked list Before deleting the node, make sure to print out ******DELETING the node with address: " and then print the node's memory address that you are Press enter to continue ! Adding some pickles to the linked list! Now printing out the pickles: -- Node 1 with memory address Oxb47ee8 Pickle Type: Bread-and-butter Bumpy Skin? no Sweet? yes ----- Node 2 with memory address Oxb40590 Pickle Type: Gherkin Bumpy Skin? yes Sweet? yes ----- Node 3 with memory address Oxb41610 Pickle Type: Kosher Dill Bumpy Skin? yes Sweet? no -----Node 4 with memory address Oxb41638 Pickle Type: Hungarian Bumpy Skin? no Sweet? no ---Node 5 with memory address oxb41660 Pickle Type: Lime Bumpy Skin? no Sweet? no Which pickle do you want to eat (and therefore remove from the list)? Choose the node number (1-5): 1 -----DELETING the node with address: Oxb47ee8 Would you like to display the list of pickles again? (y)

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

Students also viewed these Databases questions