Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ .h programming , need help implementing the updates to four .h files : PLEASE LABEL WHICH CODE GOES TO WHAT FILE IN THE ANSWER!

C++ .h programming , need help implementing the updates to four .h files :

PLEASE LABEL WHICH CODE GOES TO WHAT FILE IN THE ANSWER! THANKS

image text in transcribedimage text in transcribed

What is done so far : will provide test cases as well so you know what is right so you dont write something i dont need.

Node.h:

#pragma once

template

class List;

//This class represents a node in a linked list

//Do not modify anything in this file

template

class Node{

friend class List;

private:

T value; //value stored by this node

Node * next; //pointer to the next node in list

public:

Node(T v){

value = v;

next = nullptr;

}

};

List.h::

#pragma once

#include

#include

#include "Node.h"

using namespace std;

//This class represents a linked list of node objects

//Do not modify anything in the class interface

template

class List{

private:

Node * start; //pointer to the first node in this list

int mySize; //size (or length) of this list

public:

List();

~List();

int size();

bool empty();

void insertStart(T);

void insertEnd(T);

void insertAt(T, int);

void removeStart();

void removeEnd();

void removeAt(int);

T getFirst();

T getLast();

T getAt(int);

int find(T);

//Print the name and this list's size and values to stdout

//This function is already implemented (no need to change it)

void print(string name){

cout

cout

cout

Node * iterator = start;

while(iterator != nullptr){

cout value

iterator = iterator->next;

}

cout

}

}; //end of class interface (you may modify the code below)

//Implement all of the functions below

//Construct an empty list by initializig this list's instance variables

template

List::List(){

}

//Destroy all nodes in this list to prevent memory leaks

template

List::~List(){

}

//Return the size of this list

template

int List::size(){

}

//Return true if this list is empty

//Otherwise, return false

template

bool List::empty(){

}

//Create a new node with value, and insert that new node

//into this list at start

template

void List::insertStart(T value){

}

//Create a new node with value, and insert that new node

//into this list at end

template

void List::insertEnd(T value){

}

//Create a new node with value , and insert that new node at position j

template

void List::insertAt(T value, int j){

}

//Remove node at start

//Make no other changes to list

template

void List::removeStart(){

}

//Remove node at end

//Make no other changes to list

template

void List::removeEnd(){

}

//Remove node at position j

//Make no other changes to list

template

void List::removeAt(int j){

}

//Return the value of the first node in the Linked List,

//If no first node, return the default constructed value: T()

template

T List::getFirst(){

}

//Return the value of the last node in the Linked List,

//If no first node, return the default constructed value: T()

template

T List::getLast(){

}

//Return the value of the node at position j in the Linked List,

//If no first node, return the default constructed value: T()

template

T List::getAt(int j){

}

//Return the position of the (first) node whose value is equal to the key

//Otherwise, return -1

template

int List::find(T key){

}

ListStack.h:

#pragma once

//This class represents a Stack implemented via Linked List

//Do not modify anything in the class interface

template

class ListStack{

private:

List stack;

public:

ListStack();

~ListStack();

int size();

bool empty();

void push(T);

T pop();

//Print the name and this ListStack's size and values to stdout

//This function is already implemented (no need to change it)

void print(string name){

stack.print(name);

}

}; //end of class interface (you may modify the code below)

//Implement all of the functions below

//Construct an empty ListStack by initializing this ListStack's instance variables

template

ListStack::ListStack(){

}

//Destroy all nodes in this ListStack to prevent memory leaks

template

ListStack::~ListStack(){

}

//Return the size of this ListStack

template

int ListStack::size(){

}

//Return true if this ListStack is empty

//Otherwise, return false

template

bool ListStack::empty(){

}

//Create a node with value and push it onto the stack

template

void ListStack::push(T value){

}

//Pop a node from the Stack.

//Note that here that includes both removing the node from the stack

//AND returning its value.

template

T ListStack::pop(){

}

ListQueue.h:

#pragma once

//This class represents a Queue implemented via Linked List

//Do not modify anything in the class interface

template

class ListQueue{

private:

List queue;

public:

ListQueue();

~ListQueue();

int size();

bool empty();

void enqueue(T);

T dequeue();

//Print the name and this ListQueue's size and values to stdout

//This function is already implemented (no need to change it)

void print(string name){

queue.print(name);

}

}; //end of class interface (you may modify the code below)

//Implement all of the functions below

//Construct an empty ListQueue by initializing this ListQueue's instance variables

template

ListQueue::ListQueue(){

}

//Destroy all nodes in this ListQueue to prevent memory leaks

template

ListQueue::~ListQueue(){

}

//Return the size of this ListQueue

template

int ListQueue::size(){

}

//Return true if this ListQueue is empty

//Otherwise, return false

template

bool ListQueue::empty(){

}

//Create a new node with value, and insert that new node

//into this ListQueue in its correct position

template

void ListQueue::enqueue(T value){

}

//Dequeue an element from the queue.

//Note that here that means both removing it from the list

//AND returning the value

template

T ListQueue::dequeue(){

}

(Main functions for a subset of the test cases : T#.cpp is the main function for test case #, returns 0 when test case passes, returns 1 when test case fails.)

Case 1 :

#include "List.h" #include "Node.h" #include #include #include

using namespace std;

int main() { List list1; for (int i=1, j = 1; i

// This can be an ofstream as well or any other ostream stringstream buffer;

// Save cout's buffer here streambuf *sbuf = cout.rdbuf();

// Redirect cout to our stringstream buffer or any other ostream cout.rdbuf(buffer.rdbuf());

// Use cout as usual // cout

list1.print("list");

int test[9]; string bob; // This section skips the info printout // section of the print function buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob;

int test2[] = {4,-8,16,-32,64,-128,256,-512,1024}; for (int i=0; i> bob; test[i] = stoi(bob); // ASSERT_EQ(test[i],test2[i]); }

// When done redirect cout to its old self cout.rdbuf(sbuf);

for (int i=0; i

Case 16 :

#include "ListStack.h" #include #include #include

using namespace std;

int main() { ListStack stack3; char c[] = {'m', 'l', 'k', 'j', 'i', 'h', 'e', 'c', 'b', 'a', 'p', 'z'}; for(int i = 0; i

// This can be an ofstream as well or any other ostream stringstream buffer;

// Save cout's buffer here streambuf *sbuf = cout.rdbuf();

// Redirect cout to our stringstream buffer or any other ostream cout.rdbuf(buffer.rdbuf());

// Use cout as usual // cout

stack3.print("list");

char test[12]; char test2[] = {'z', 'p', 'a', 'b', 'c', 'e', 'h', 'i', 'j', 'k', 'l', 'm'}; string bob; // This section skips the info printout // section of the print function buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob; buffer >> bob;

for (int i=0; i> bob; // test[i] = stoi(bob); test[i] = bob.at(0); }

// When done redirect cout to its old self cout.rdbuf(sbuf);

for (int i=0; i

PLEASE LABEL WHICH CODE GOES TO WHAT FILE IN THE ANSWER! THANKS

Part 1: Download the starter code and implement a Linked List (List class) that works with arbitrary class objects (using a class template). You are NOT allowed to use anything from the STL, only the Node class that is included in your starter code. The Node class is already implemented, you don't need to modify node.h. You will need to implement all member functions of the List class except print() which is already provided; you will modify list.h to do this. The following functions are members of List: List() and L List(): Constructor and Destructor, need to initialize members (constructor) and deallocate all nodes in list (destructor). void print(string name): Print name, size, and values. Already implemented int size(): Returns the size of the list. bool empty(): Returns true if list is empty. void insertStart(T value): Create new node with value, insert this node at the start of the list. void insertEnd(T value): Create new node with value, insert this node at the end of the list. void insertAt(T value, int j ): Create new node with value, insert this node at position j. Position 0 is the start of the list (first node), position 1 is the second node, positon 2 is the third node, and so on... void removeStart(): Remove node at the start of the list. void removeEnd(): Remove node at the end of the list. void removeAt(int j ): Remove node at position j in the list. T getFirst(): Return value of the node at the start of the list. T getLast(): Return value of the node at the end of the list. T getAt(int j ): Return value of the node at position j. int find(T value): Return the position of the first occurance of value in the list. Part 2: Implement the ListStack and ListQueue classes using the List class. Stack: Implement the functions in the ListStack class (modify ListStack.h): ListStack() and ListStack(): Constructor and Destructor, nothing extra needs to be done here for ListStack. void print(string name): Print name, size, and values. Already implemented int size(): Returns the size of the stack. bool empty(): Returns true if the stack is empty. void push(T value): Insert value onto the "top" of the stack. T pop(): Remove AND return value on the "top" of the stack. Queue: Implement the functions in the ListQueue class (modify ListQueue.h): ListQueue() and ListQueue(): Constructor and Destructor, nothing extra needs to be done here for ListQueue. void print(string name): Print name, size, and values. Already implemented int size(): Returns the size of the queue. bool empty(): Returns true if the queue is empty. void enqueue(T value): Insert value into the "back" of the queue. T dequeue(): Remove AND return value from the "front" of the queue

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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions