Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need c++ format need .h .cpp and main.cpp here is start code ************************************************************************************************************ #ifndef INTLIST_H #define INTLIST_H #include IntNode.h #include using std::ostream; class IntList {

need c++ format

need .h .cpp and main.cpp

here is start code

************************************************************************************************************

#ifndef INTLIST_H

#define INTLIST_H

#include "IntNode.h"

#include

using std::ostream;

class IntList {

public:

IntList( ) = default;

~IntList( void );

bool is_empty( void ) const;

void add_front( int newData );

int remove_front(int& oldData );

void write( ostream& outfile ) const;

private:

IntNode* head = nullptr;

// disallow copies by restricting the following to `private`:

IntList( const IntList& );

IntList& operator=( const IntList& );

};

ostream& operatorconst IntList& list );

#endif

******************************************************************************************************************

#include "IntList.h"

#include "IntNode.h"

#include

#include

using std::ostream;

IntList::~IntList()

{

int oldData;

while(!remove_front(oldData))

{

remove_front(oldData);

}

}

bool IntList::is_empty () const

{

bool check = true;

if(head)

{

check = false;

}

return check;

}

void IntList::add_front( int newData )

{

IntNode* newNode = new IntNode(newData);

newNode -> set_next(head);

head = newNode;

}

void IntList::write (ostream& outfile) const

{

IntNode* current = head;

while (current)

{

if (current -> get_next()) //current is last two element

{

outfile get_data() " get_next() -> get_data()

current = current -> get_next();

}

else

{

outfile get_data() / ) ";

current = current -> get_next();

}

}

}

ostream& operator const IntList& list)

{

list.write(outfile);

return outfile;

}

int IntList::remove_front (int& oldData)

{

IntNode* current = new IntNode(oldData);

bool status=true;

if (is_empty())

{

status = false;

}

else

{

current = head;

oldData = current -> get_data();

head = current -> get_next();

delete current;

}

return status;

}

***************************************************************************************

image text in transcribedimage text in transcribed

The Queue The queue data structure is a First-In, First-Out collection. Items are added to the queue (usually we call this action enqueue] and they line up just as you would in a line for an amusement park ride. Then, when items are removed, the one that is at the front of the queue [i.e. the one that has been waiting the longest] is removed first. We call this action Create a new header/implementation file pair named "IntQueueand-ntOueue.cpp". Use your work on the IntList in lab and your experience in specializing it to a stack as a guide. The primary difference between the general-purpose list and the queue is the way items are added and removed. The queue should only support one method of addition enqueue(and one method of removal [dequeue()). These operations will map to adding at the end of the list and removing at the front, respectively. Since queue-like operations require you to add at the end of the list, you will need to add some functionality to your IntList implementation. Add a tail pointer to the IntList (as a private attribute that is initialized appropriately). and then create an add back() method in IntList to allow items to be efficiently added at the end of the list. Don't forget to update your existing IntList methods to keep the tail pointer consistent with the state of the list! Once you have completed these changes, your list will now support all the operations necessary to operate as the underlying container for your queue. Your IntQueue class should implement the following interface: class IntQueue f public: bool is_empty const; enqueue( int operand) int dequeue void debug write( ostream& outfile const private: IntList list; ostream& operator

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

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago