Question: Write a C++ program that contains following functions: 1. bool contains (Node *list, char item) This function receives a character linked list (receives a pointer

Write a C++ program that contains following functions:

1. bool contains (Node *list, char item)

This function receives a character linked list (receives a pointer that is either a NULL pointer or a pointer pointing to the first node of a linked list) and a character. The function will return true if the character the function receives is one of the characters stored in the list, otherwise the function returns false.

2. int getLength (Node *list)

This function receives a linked list and returns the count of nodes in the list.

3. int getMax(Node *list)

This function receives an integer linked list and returns the largest integer in the list.

4. int getLast(Node *list)

This function receives an integer linked list and returns the data item in the last node of the list.

my anwser so far

source file.cpp

#include #include"Node.h" using namespace std;

void display(Node* list) { Node* curNode = list; while (curNode != NULL) { cout << curNode->getItem() << endl; curNode = curNode->getNext(); } } int getMax(Node* list) { int max = 0; Node* curNode = list; while (curNode != NULL) { if ( } return max;

} bool contains(Node* list, int item) { Node* curNode = list; while (curNode != NULL) { if (curNode->getItem() == item) return true; curNode = curNode->getNext();

} return false; } void setLastItem(Node* list, int a) { Node* curNode = list; while (curNode->getNext() != NULL) { curNode = curNode->getNext(); } }

int main() {

Node* head = NULL; Node* newNode; int newItem; int c; cout << "how many node?" << endl; cin >> c; for (int i = 0; i < c; i++) { cout << "please enter integer:" << endl; cin >> newItem; newNode = new Node(newItem, head); head = newNode;

} cout << "==============" << endl; display(head); setLastItem(head, 100); cout << "=============" << endl; display(head); cout << "================" << endl;

}

and here is the header file

#ifndef _NODE #define _NODE

template class Node { private: ItemType item; Node* next; public: Node(); //default constructor Node(const ItemType& anItem);//none default constructor Node(const ItemType& anItem, Node* nextPtr); //none default constructor void setItem(const ItemType& anItem); void setNext(Node* nextPtr); ItemType getItem() const; Node* getNext() const; }; template Node::Node() { next = NULL; } template Node::Node(const ItemType& anItem) { item = anItem; next = NULL; } template Node::Node(const ItemType& anItem, Node* nextPtr) { item = anItem; next = nextPtr; } template void Node::setItem(const ItemType& anItem) { item = anItem; } template void Node::setNext(Node* nextPtr) { next = nextPtr; } template ItemType Node::getItem() const { return item; } template Node* Node::getNext() const { return next; } #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!