Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Use the array based list headers for queue. Call your function to test its functionality. Here are the headers:
#ifndef H_arrayListType
#define H_arrayListType
#include <iostream>
using namespace std;
template <class elemType>
class arrayListType
{
public:
const arrayListType<elemType>&
operator=(const arrayListType<elemType>&);
//Overloads the assignment operator
bool isEmpty() const;
//Function to determine whether the list is empty
//Postcondition: Returns true if the list is empty;
// otherwise, returns false.
bool isFull() const;
//Function to determine whether the list is full
//Postcondition: Returns true if the list is full;
// otherwise, returns false.
int listSize() const;
//Function to determine the number of elements in
//the list.
//Postcondition: Returns the value of length.
int maxListSize() const;
//Function to determine the maximum size of the list
//Postcondition: Returns the value of maxSize.
void print() const;
//Function to output the elements of the list
//Postcondition: Elements of the list are output on the
// standard output device.
bool isItemAtEqual(int location, const elemType& item) const;
//Function to determine whether item is the same as
//the item in the list at the position specified
//by location.
//Postcondition: Returns true if the list[location]
// is the same as item; otherwise,
// returns false.
// If location is out of range, an
// appropriate message is displayed.
virtualvoid insertAt(int location, const elemType& insertItem) = 0;
//Function to insert insertItem in the list at the
//position specified by location.
//Note that this is an abstract function.
//Postcondition: Starting at location, the elements of
// the list are shifted down,
// list[location] = insertItem; length++;
// If the list is full or location is out of
// range, an appropriate message is displayed.
virtualvoid insertEnd(const elemType& insertItem) = 0;
//Function to insert insertItem an item at the end of
//the list. Note that this is an abstract function.
//Postcondition: list[length] = insertItem; and length++;
// If the list is full, an appropriate
// message is displayed.
void removeAt(int location);
//Function to remove the item from the list at the
//position specified by location
//Postcondition: The list element at list[location] is
// removed and length is decremented by 1.
// If location is out of range, an
// appropriate message is displayed.
void retrieveAt(int location, elemType& retItem) const;
//Function to retrieve the element from the list at the
//position specified by location
//Postcondition: retItem = list[location]
// If location is out of range, an
// appropriate message is displayed.
virtualvoid replaceAt(int location, const elemType& repItem) = 0;
//Function to replace repItem the elements in the list
//at the position specified by location.
//Note that this is an abstract function.
//Postcondition: list[location] = repItem
// If location is out of range, an
// appropriate message is displayed.
void clearList();
//Function to remove all the elements from the list
//After this operation, the size of the list is zero.
//Postcondition: length = 0;
virtualint seqSearch(const elemType& searchItem) const = 0;
//Function to search the list for searchItem.
//Note that this is an abstract function.
//Postcondition: If the item is found, returns the
// location in the array where the item is
// found; otherwise, returns -1.
virtualvoid remove(const elemType& removeItem) = 0;
//Function to remove removeItem from the list.
//Note that this is an abstract function.
//Postcondition: If removeItem is found in the list,
// it is removed from the list and length
// is decremented by one.
arrayListType(int size = 100);
//Constructor
//Creates an array of the size specified by the
//parameter size. The default array size is 100.
//Postcondition: The list points to the array, length = 0,
// and maxSize = size;
arrayListType (const arrayListType<elemType>& otherList);
//Copy constructor
virtual ~arrayListType();
//Destructor
//Deallocate the memory occupied by the array.
protected:
elemType *list; //array to hold the list elements
int length; //variable to store the length of the list
int maxSize; //variable to store the maximum
//size of the list
};
template <class elemType>
bool arrayListType<elemType>::isEmpty() const
{
return (this->length == 0);
}
template <class elemType>
bool arrayListType<elemType>::isFull() const
{
return (this->length == this->maxSize);
}
template <class elemType>
int arrayListType<elemType>::listSize() const
{
return this->length;
}
template <class elemType>
int arrayListType<elemType>::maxListSize() const
{
return this->maxSize;
}
template <class elemType>
void arrayListType<elemType>::print() const
{
for (int i = 0; i < this->length; i++)
cout << list[i] << " ";
cout << endl;
}
template <class elemType>
bool arrayListType<elemType>::isItemAtEqual(int location,
const elemType& item) const
{
if (location < 0 || location >= this->length)
{
cout << "The location of the item to be removed "
<< "is out of range." << endl;
returnfalse;
}
else
return (list[location] == item);
}
#endif
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 1 images
Knowledge Booster
Similar questions
- #include #include using std::cout; using std::vector; class StatSet { private: HCreate a vector of doubles that is called "numbers." public: //Nothing to do in the constructor. StatSet() } // Add a new number to the set. vòid add_num(double num) { } double mean() { //Sum up the values and return the average. double sum = 0; //Write a loop that would iterate through the vector. sum += numbers[i]; return sum / numbers.size(); } double median() //Before calculating the median, we must sort the //array.arrow_forwardDuplicate Set This function will receive a list of elements with duplicate elements. It should add all of the duplicate elements to a set and return the set containing the duplicate elements. A duplicate element is an element found more than one time in the specified list. The order of the set does not matter. Signature: public static HashSet<Object> duplicateSet(ArrayList<Object> list) Example: INPUT: [2, 4, 5, 3, 3, 5] OUTPUT: {5, 3}arrow_forwardComplete the expand () function template. The template takes a reference to a unique_ptr pointing to an array and doubles the size of the array. memory.cpp 1 #include 2 #include 3 #include 4 using namespace std; template void expand(unique_ptr& a, int size) { 7 8 9 10 11 12 } 13 14 int main() 15 { 16 unique_ptr a{new int[5]{ 10, 1, 5, 6, 4 }}; 17 18 expand (a, 5); // resize to hold 10 elements 19 20 for (int i = 5; i {" « a[0]; for (int i = 1; i < 10; i++) { cout « ", cout « "}" « endl; } 22 23 « a[i]; } 24 25arrow_forward
- Array_based circular queue: Define the class Queue using one dimensional circular array representation with no implementation; i.e. declare the data members, and the function members only (Enqueue, Dequeue, IsEmpty, GetHead etc.). Implement the Ennqueue method of the above classarrow_forwardStudent* func () { unique ptr arr[] make_unique ("CSC340") }; // #1 Insert Code int main () ( // #2 Insert Code [ #1 Insert Code]: Write code to keep all the object(s) which element(s) of array arr owns alive outside of the scope of func. [#2 Insert Code]: Write code to have a weak_ptr monitor the object which survived; Then test if it has any owner; Then properly destroy it; Then test again if has any owner; Then destroy the Control Block.arrow_forwarddef animals(animal_dict, target): """ Filter animals based on the target category. :param animal_dict: A dictionary mapping animals to their categories. :type animal_dict: dict :param target: The target category to filter animals. :type target: str :return: A list of animals belonging to the target category. :rtype: list animals_dict = {"dogs": "mammals", "snakes": "reptiles", \ "dolphins": "mammals", "sharks": "fish"} >>> target = "mammals" >>> animals(animals_dict, target) ['dogs', 'dolphins'] >>> animals_dict = {True: "mammals"} >>> animals(animals_dict, target) # This will raise an AssertionError Traceback (most recent call last): ... AssertionError: Target should be provided and not None """ assert target is not None, "Target should be provided and not None" assert isinstance(animal_dict, dict) assert all(isinstance(animal, str) for animal in animal_dict.keys())…arrow_forward
- C++ The List class represents a linked list of dynamically allocated elements. The list has only one member variable head which is a pointer that leads to the first element. See the following code for the destructor to List. ~ List () { for (int i = 0; i <size (); i ++) { pop_back (); } } What problems does the destructor have? Select one or more options: 1. There are no parameters for the destructor. 2. The return value from pop_back (if any) is nerver handled. 3. The destructor will create a stack overflow. 4. The destructor will create dangling pointers. 5.The destructor will create memory leaks. 6.The destructor will create undefined behavior (equivalent to zero pointer exception). 7.The condition must be: i <size () - 1 8. There is at least one problem with the destructor, but none of the above.arrow_forwardRe-write Sample Program 11.2 so that it works for an array of structures. Write the program so that it compares 6 circles. You will need to come up with a new way of determining which circle’s center is closest to the origin. Sample code 11.2 #include <iostream>#include <cmath> // necessary for pow function#include <iomanip>using namespace std;struct circle // declares the structure circle{ // This structure has 6 membersfloat centerX; // x coordinate of centerfloat centerY; // y coordinate of centerfloat radius;float area;float circumference;float distance_from_origin;};const float PI = 3.14159;int main(){circle circ1, circ2; // defines 2 circle structure variablescout << "Please enter the radius of the first circle: ";cin >> circ1.radius;cout << endl<< "Please enter the x-coordinate of the center: ";cin >> circ1.centerX;cout << endl<< "Please enter the y-coordinate of the center: ";cin >>…arrow_forwardC programming fill in the following code #include "graph.h" #include <stdio.h>#include <stdlib.h> /* initialise an empty graph *//* return pointer to initialised graph */Graph *init_graph(void){} /* release memory for graph */void free_graph(Graph *graph){} /* initialise a vertex *//* return pointer to initialised vertex */Vertex *init_vertex(int id){} /* release memory for initialised vertex */void free_vertex(Vertex *vertex){} /* initialise an edge. *//* return pointer to initialised edge. */Edge *init_edge(void){} /* release memory for initialised edge. */void free_edge(Edge *edge){} /* remove all edges from vertex with id from to vertex with id to from graph. */void remove_edge(Graph *graph, int from, int to){} /* remove all edges from vertex with specified id. */void remove_edges(Graph *graph, int id){} /* output all vertices and edges in graph. *//* each vertex in the graphs should be printed on a new line *//* each vertex should be printed in the following format:…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY