You are to write well-formed C++ code that defines and implements a new public member function of the attached doubly linked list data structure, which is implemented using two dummy nodes.
Implement your function using recursion. That is, your new public member function must call a new private, recursive helper function. A non-recursive version of the helper function will get no credit. The helper function should not have any loops at all. Do not use any global variables. Both new functions should call existing member functions when appropriate. Refer to the attached code for the existing functions available. The attachment is for reference only. Write your response in the space below clearly indicating which is the public and which is the private function. Click here to view the attachment.
You cannot add additional attributes to the class. You may assume the default and copy constructors, and all the operators (e.g., <, <=, ==, +, ++, =, +=, <<) are defined for element type Data_t. The description of the new public function you are to write is:
Iterator findFirst( const Data_t & value );
This function takes one argument and returns an iterator to the node containing the first occurrence of the supplied value, or an iterator to the trailing dummy node if the value is not contained in the list. For example, if the list is
_head → dummy_node ↔ 10 ↔ 23 ↔ 15 ↔ 23 ↔ 15 ↔ dummy_node ← _tail
↑ ↑
findFirst(23) findFirst(20)
then findFirst(20) returns an iterator to the trailing dummy node, but findFirst(23) returns an iterator to the first occurrence of 23..
// code
// Seaction 1
#include <iostream>
using namespace std;
template <class T>
struct Node
{
T data;
Node *next;
};
template <class T>
class linked_list
{
Node<T> *_head, *_trail;
// recursive helper function
Iterator find_first_helper(Node *head, const Data_t &value)
{
// trail node, not found
if (head == this->_trail)
{
return this->_trail;
}
// found
if (head->data == value)
return head;
// recursive call
return find_first_helper(head->next, value);
}
public:
Iterator findFirst(const Data_t &value)
{
// call helper function with 2 next for 2 dummy nodes
return find_first_helper(this->_head->next->next, value);
}
};
int main(int argc, char const *argv[])
{
}
THANK YOU!!! PLZ IGNORE SMALL MISTAKES
PLZ VOTE!!!
You are to write well-formed C++ code that defines and implements a new public member function...
v. 15 points) implementing data structure operations C++ code for a new public member function to be added to the doubly linked list data structure used in class. Return the average value of all elements in the list ple a list of integers) Throws a length error exception if the list is empty. template «typename E> E& 0; average You may use loops or recursion as needed. If necessary, you may add private helper function0s) The definition of the DLinkedList...
IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. 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...
Add a public member function to the BST class below that returns the size of the tree—the number of the nodes in the tree. For simplicity, the class contains only the key and not a value. You may add any helper functions you find necessary. (Hint: think recursion) template <typename T> struct Node { T key; Node<T>* left; Node<T>* parent; Node<T>* right; }; template <typename T> class BST { private: Node<T>* root; public: BST():...
***Using C++ and also please label "a" and "c" accordingly.
Thank you!!****
a) Write the member function void deleteNode() that will delete
the first node from the linked list.
b) Modify the LList to create a data member Node *cur that
points to the current node. Write the following member
functions:
• void forward() that moves the cur pointer to the next
node.
• void backward() that moves the cur pointer to the previous
node.
• void delete() that removes...
C++ Write a public member function incrementNodes for a BinaryTree class that will add 1 to each item in the binary tree. If this function calls any other function, you must write the code for that function as well. Note that the class BinaryTree has a private member variable root which is a Node pointer.
In Java. How would this method look?
LinkedBinaryTree.java
import java.util.Iterator;
public class LinkedBinaryTree implements BinaryTreeADT {
private BinaryTreeNode root;
/**
* Creates an empty binary tree.
*/
public LinkedBinaryTree() {
root = null;
}
/**
* Creates a binary tree from an existing root.
*/
public LinkedBinaryTree(BinaryTreeNode root) {
this.root = root;
}
/**
* Creates a binary tree with the specified element...
Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...
C++ program, item.cpp implementation.
Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...
PLEASE USE C++ Source Code
Attached is a linked list with 2 nodes. You can use this or
write a similar one. The assignment is to write 2 functions. One
function will add another node at the end of the list. The other
function will delete a node. Don't forget - No dangling pointers
!
Example linked source code attached below
#include<iostream>
using namespace std;
class Node
{
int data;
Node *next;
public:
void setdata(int d) {data = d;}
void...
Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...