Question
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?
=====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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started