Question

(C++) Suppose you want to use a linked list where the items stored in the list...

(C++) Suppose you want to use a linked list where the items stored in the list are strings from the standard library string class, how would you change the node1.h header file?

Header File:

#ifndef MAIN_SAVITCH_NODE1_H
#define MAIN_SAVITCH_NODE1_H
#include <cstdlib> // Provides size_t and NULL

namespace main_savitch_5 {

class node {
public:

// TYPEDEF
typedef double value_type;
// CONSTRUCTOR
node(const value_type& init_data=value_type( ), node* init_link=NULL)

{ data_field = init_data; link_field = init_link; }
// MODIFICATION MEMBER FUNCTIONS
node* link( ) { return link_field; }
void set_data(const value_type& new_data) { data_field = new_data; } void set_link(node* new_link) { link_field = new_link; }

// CONST MEMBER FUNCTIONS
value_type data( ) const { return data_field; } const node* link( ) const { return link_field; }

private:
value_type data_field; node *link_field;

};

// FUNCTIONS for the linked-list toolkit
std::size_t list_length(const node* head_ptr);
void list_head_insert(node*& head_ptr, const node::value_type& entry); void list_insert(node* previous_ptr, const node::value_type& entry); node* list_search(node* head_ptr, const node::value_type& target); const node* list_search

(const node* head_ptr, const node::value_type& target);
node* list_locate(node* head_ptr, std::size_t position);
const node* list_locate(const node* head_ptr, std::size_t position); void list_head_remove(node*& head_ptr);
void list_remove(node* previous_ptr);
void list_clear(node*& head_ptr);
void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr);

} #endif

Homework Answers

Answer #1

Here the node1.h will have to specify that the value_type it is holding is of string type instead of the double type.

For Example Here is the changed code:

#include <string>

class node {
public:

// TYPEDEF
typedef string value_type;
// CONSTRUCTOR
node(const value_type& init_data=value_type( ), node* init_link=NULL)

{ data_field = init_data; link_field = init_link; }
// MODIFICATION MEMBER FUNCTIONS
node* link( ) { return link_field; }
void set_data(const value_type& new_data) { data_field = new_data; } void set_link(node* new_link) { link_field = new_link; }

// CONST MEMBER FUNCTIONS
value_type data( ) const { return data_field; } const node* link( ) const { return link_field; }

private:
value_type data_field; node *link_field;

};

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the implementation of a non-member function Node* deleteSecond(Node* head_ptr), where Node is a class defined...
Write the implementation of a non-member function Node* deleteSecond(Node* head_ptr), where Node is a class defined on page 257. The function takes as input a pointer to the head of a linked list consisting of numbers. The function should remove the second item in the list. If the list had only one item, the function should delete that item. If the list was empty, then let the list remain empty. In all cases return the new head of the list...
#ifndef BAG_H #define BAG_H #include <cstdlib> // Provides size_t using namespace std; class bag { public:...
#ifndef BAG_H #define BAG_H #include <cstdlib> // Provides size_t using namespace std; class bag { public: // TYPEDEFS and MEMBER CONSTANTS typedef int value_type; typedef std::size_t size_type; static const size_type CAPACITY = 30; // CONSTRUCTOR bag() {used = 0;} // MODIFICATION MEMBER FUNCTIONS size_type erase(const value_type& target); bool erase_one(const value_type& target); void insert(const value_type& entry); void operator +=(const bag& addend); void sort(const bag& b); //Sort the array in the bag object // CONSTANT MEMBER FUNCTIONS size_type size( ) const {...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write...
Create a C++ project. Download and add the attached .h and .cpp to the project. Write an implementation file to implement the namespace declared in the attached CSCI361Proj5.h. Name the implementation file as YourNameProj5.cpp and add it to the project. Run the project to see your grade. .h file: // Provided by: ____________(your name here)__________ // Email Address: ____________(your email address here)________ // FILE: link.h // PROVIDES: A toolkit of 14 functions for manipulating linked lists. Each // node of...
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const...
could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const size_t& count) class ListNode { public: typedef int value_type; ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }    //Assessor value_type getDatum () const { return datum; } ListNode const* getNext () const { return next; }    //Mutator void setDatum (const value_type& d) {datum = d; } ListNode* getNext () { return next; } void...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
8.19 LAB: Grocery shopping list (linked list: inserting at the end of a list) PLEASE ANSWER...
8.19 LAB: Grocery shopping list (linked list: inserting at the end of a list) PLEASE ANSWER IN C++ Given main(), define an InsertAtEnd() member function in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added...
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT