Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code for a Linked list: template class Node { public: Node ( ) ; Node ( T value, Node * nextNode )

Consider the following code for a Linked list:
template
class Node
{
public:
Node();
Node(T value, Node* nextNode);
T data;
Node* next;
};
template
class LinkedList
{
public:
LinkedList();
Node* getHead() const; // return the head pointer
Node* getTail() const; // returns the tail pointer
void ListAppend(T value); // inserts an element at the end of the list
void listPrepend(T value); //inserts a n element at the head of the list
void insertAfter(Node* curNode, T value); // Insert value after the curNode
void removeAfter(Node* curNode); // remove Node after CurNode
void removeHead(); // Removes the first element
void removeTail(); // removes the last element
void printList() const; // print the elements of the linked list
private:
Node* head;
Node* tail;
};
Please add the following functions to the class LinkedList
a) getLength(): returns the number of items in the LinkedList.
b) search(T element) : searches for the element in the LinkedList, returns a pointer to the element if found, otherwise returns NULL.
I already have some pseudocode for this:
search(list, key){
curNode = listhead
while (curNode is not null){
if (curNodedata == key){
return curNode
}
curNode = curNodenext
}
return null
}
c) Write an iterative implementation of a function that receives the head node of a singly Linked list void printEven(Node * l). The function goes through the list and prints all the even elements in the list.
d) Give a recursive implementation of this function.
e) Please explain so that I can understand what you did.

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

1. Walk slowly; then be as still as possible.

Answered: 1 week ago

Question

=+2. Are you happy to pay a price premium for CSR products?

Answered: 1 week ago