Purchase Solution

Write the function definition as a recursive search using C++

Not what you're looking for?

Ask Custom Question

A sequential search member function of SortedType has the following prototype:
void SortedType: : Search(int value, bool& found) ;
a. Write the function definition as a recursive search, assuming a linked list implementation.
b. Write the function definition as a recursive search, assuming an array-based implementation.

Purchase this Solution

Solution Summary

The solution gives a complete C++ code to write the function definition as a recursive search, assuming both a linked list implementation and an array-based implementation.

Solution Preview

Part a

Recursive search

#include<iostream>
using namespace std;

int recursiveSequential( int a[], int size, int value ) {

if( size == 0 )
return -1;
if( value == a[ size - 1 ] )
return size - 1;
return recursiveSequential( a, size - 1, value );
}

int main () {

int const length = 10;
int searchV;
int list[10] = { 2, 3, 4, 5, 20, 40, 80, 45, 99, 0};

cout << "Please enter the value to be searched" <<endl;
cin>> search;

cout << recursiveSequential(list, length, searchV) << endl;

return 0;
}

using link list function

template<typename T>
Iterator<T> LinkedList<T>::find(T value)
{

Node<T>* pos = NULL;
Iterator<T> res=pos.position;

Node<T>* current = first;
Iterator<T> iter=current.position;

while (current != NULL) ...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.