472,976 Members | 1,236 Online

Recursive Search

Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.

I would GREATLY appreciate it!!!

Aug 10 '07 #1
10 2485
As******@msn.com wrote:
Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?
Aug 10 '07 #2
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.

What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.

Aug 10 '07 #3
As******@msn.com wrote:
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
>Ashee...@msn.com wrote:
>>Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?

*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.
A linked list is one element and one linked list or the empty linked list.

Is that enough of a hint ?
Aug 10 '07 #4
On Aug 9, 9:21 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.

A linked list is one element and one linked list or the empty linked list.

Is that enough of a hint ?
****************************
Not really...

Aug 10 '07 #5
As******@msn.com wrote:
On Aug 9, 9:21 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
>Ashee...@msn.com wrote:
>>On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.
A linked list is one element and one linked list or the empty linked list.

Is that enough of a hint ?

****************************
Not really...
Try writing the data structure for a linked list and the outline of a
function. Once you have that think about how to operate on a linked
list like I described above i.e. an element and another linked list, or
the empty list.
Aug 10 '07 #6
On Aug 9, 9:44 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:21 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
Hello Everyone!
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.
A linked list is one element and one linked list or the empty linked list.
Is that enough of a hint ?
****************************
Not really...

Try writing the data structure for a linked list and the outline of a
function. Once you have that think about how to operate on a linked
list like I described above i.e. an element and another linked list, or
the empty list.- Hide quoted text -

- Show quoted text -
Hmmm...ok. Here is what I have so far.
Here is the .cpp file:

#include <iostream>
using namespace std;
#include "List.h" // header file
template< typename NODETYPE>
List< NODETYPE >::List()
:firstPtr( 0 )
{
} // end default constructor

template< typename NODETYPE>
List< NODETYPE >::~List()
{
if ( !isEmpty() )//list is not empty
{
cout << "Destroying Nodes...\n";
ListNode< NODETYPE *currentPtr = firstPtr;
ListNode< NODETYPE *tempPtr;

while ( currentPtr != 0 ) //deletes nodes
{
tempPtr = currentPtr;
cout << tempPtr->Data << '\n';
currentPtr = currentPtr->nextPTR;
delete tempPtr;
}
}

//insert at front
template< typename NODETYPE>
void List< NODETYPE >::insertAtFront(const NODETYPE &value )
{
ListNode< NODETYPE *newPtr = getNewNode( value ); //new node

if( isEmpty() ) //the list IS empty
firstPtr = lastPtr = newPtr;
else //if not empty
{
newPtr->nextPtr = firstPtr;
firstPtr = newPtr;
}
}

//insert at back
template< typename NODETYPE>
void List< NODETYPE >::insertAtBack(const NODETYPE &value )
{
ListNode< NODETYPE *newPtr = getNewNode( value ); //new node

if( isEmpty() ) //the list IS empty
firstPtr = lastPtr = newPtr;
else //if not empty
{
lastPtr->nextPtr = newPtr;
lastPtr = newPtr;
}
}

//delete from front
template< typename NODETYPE>
bool List< NODETYPE >::removeFromFront(const NODETYPE &value )
{
if( isEmpty() )
return false; //unsuccessful delete
else
{
ListNode< NODETYPE *tempPtr = firstPtr;

if (firstPtr == lastPtr )
firstPtr = lastPtr = 0; //no more nodes
else
firstPtr = firstPtr->nextPTR;
value = tempPtr->data;
delete tempPtr;
return true; //successful delete
}
}

//delete from back
template< typename NODETYPE>
bool List< NODETYPE >::removeFromBack( NODETYPE &value )
{
if( isEmpty() )
return false;
else
{
ListNode< NODETYPE *tempPtr = lastPtr;
if (firstPtr == lastPtr )
firstPtr = lastPtr = 0;
else
{
ListNode< NODETYPE *currentPtr = firstPtr;

//locate second-to-last element
while ( currentPtr->nextPtr != lastPtr )
currentPtr = currentPtr->nextPtr; //move to next node

lastPtr = currentPtr; //remove last node
currentPtr->nextPtr = 0; //becomes the last node
}

value = tempPtr->data; //return value from old last node
delete tempPtr; //reclaim former last node
return true; //delete successful
}
} //ends removeFromBack function

//is list empty?
template< typename NODETYPE >
bool List< NODETYPE >::isEmpty() const
{
return firstPtr == 0;
}//end isEmpty function

//return pointer
template< typename NODETYPE >
ListNode< NODETYPE *List< NODETYPE >::getNewNode(const NODETYPE
&value )
{
return new ListNode< NODETYPE >( value );
}//end getNewNode

//display list
template< typename NODETYPE >
void List< NODETYPE >::print() const
{
if ( isEmpty() )
{
cout << "The list is empty\n\n";
return;
}
ListNode< NODETYPE *currentPtr = firstPtr;

cout << "The list is: ";

while ( currentPtr != 0 ) //get element data
{
cout << currentPtr->data << ' ';
currentPtr = currentPtr->nextPtr;
}

cout << "\n\n";
}

int main()
{
List();
void insertAtFront(5);
void insertAtFront(4);
int list;
}//end main

Aug 10 '07 #7
As******@msn.com wrote:
On Aug 9, 9:44 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
>Ashee...@msn.com wrote:
>>On Aug 9, 9:21 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
>Ashee...@msn.com wrote:
>>Hello Everyone!
>>I have a linked list and am trying to include a recursive search.
>>However, I am having trouble understanding how I would go about that.
>>I don't quite understand a recursive search....would any of you be so
>>kind to explain it to me...maybe include some examples.
>What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.
A linked list is one element and one linked list or the empty linked list.
Is that enough of a hint ?
****************************
Not really...
Try writing the data structure for a linked list and the outline of a
function. Once you have that think about how to operate on a linked
list like I described above i.e. an element and another linked list, or
the empty list.- Hide quoted text -

- Show quoted text -

Hmmm...ok. Here is what I have so far.
Here is the .cpp file:
What do you want your search function signature to look like ?
Aug 10 '07 #8
On Aug 9, 10:08 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:44 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:21 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
On Aug 9, 9:01 pm, Gianni Mariani <gi3nos...@mariani.wswrote:
Ashee...@msn.com wrote:
>Hello Everyone!
>I have a linked list and am trying to include a recursive search.
>However, I am having trouble understanding how I would go about that.
>I don't quite understand a recursive search....would any of you be so
>kind to explain it to me...maybe include some examples.
What do you know about "recursive" functions ?
*****
I know that recursive functions are used in sorting and you can use
recursive functions to add a collection of values. Such as adding the
fibonacci sequence.
A linked list is one element and one linked list or the empty linked list.
Is that enough of a hint ?
****************************
Not really...
Try writing the data structure for a linked list and the outline of a
function. Once you have that think about how to operate on a linked
list like I described above i.e. an element and another linked list, or
the empty list.- Hide quoted text -
- Show quoted text -
Hmmm...ok. Here is what I have so far.
Here is the .cpp file:

What do you want your search function signature to look like ?- Hide quoted text -

- Show quoted text -
See...that is what I am very confused on. I just don't get it.

Aug 10 '07 #9
As******@msn.com wrote:
I have a linked list and am trying to include a recursive search.
However, I am having trouble understanding how I would go about that.
I don't quite understand a recursive search....would any of you be so
kind to explain it to me...maybe include some examples.

I would GREATLY appreciate it!!!
I strongly suggest you use a loop instead of a recursive function. If
you have to make a recursive function because this is homework, then
write the looping version and convert it.

Here's a typical loop.

for ( <init; <cond; <update)
<body>

This can be converted to two functions: the main function and the helper
recursive function.

recFunc() {
loopVar = <init>
recHelperFunc( loopVar );
}

recHelperFunc( loopVar ) {
if ( <cond) {
<body>
<update>
recHelperFunc( loopVar ); // recursive call
}
}
Aug 10 '07 #10
As******@msn.com wrote:
See...that is what I am very confused on. I just don't get it.
Ah.

In general you need to know what you're searching for so something like
this would be the entry point:
iterator SearchEqual(const NODETYPE &value )
{
return SearchNodes( firstPtr, value );
}
iterator SearchEqualNodes(Node * ptr, const NODETYPE &value )
{
if ( ptr )
{
if ( value == ptr->Value )
{
return iterator( ptr );
}

return SearchNodes(ptr->nextPtr(), value );
}

return end();
}
Aug 10 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

 3 by: alanwo | last post by: For recursive search for files, like http://support.microsoft.com/default.aspx?scid=KB;EN-US;306666, it may lead to "out of stack" error if searching too many files, say millions of files. Do you... 7 by: Jon Slaughter | last post by: #pragma once #include class empty_class { }; template class RDES_T { 2 by: RML | last post by: hi guys i have searched all day and cannot find the code i am looking for. i am new to c# so please bear with me ;) i want to write a console app that simly lists in the console window, all... 2 by: Inso Haggath | last post by: Good day, Firstly, yes, i am a first year student, and yes, i need help with my home work. But i really want to learn something from it. The task was to find all words in a file that are... 0 by: Dianna | last post by: Hi, I am doing a recursive search of my treeview. All I am doing is iterating through the nodes and checking if my tag = my id. It seems to works, finds the ID, selects it and exits. However,... 3 by: Gabe Matteson | last post by: I am trying to set the maximum value of the progress bar so that when a user searches through the specified directory they can see their status. the progress bar name is on form2 and is named... 3 by: Robertico | last post by: I'am new to php and have a question about a recursive file search. I'd like to do a recursive search for jpg-files and add the filenames (full path) to a mysql database. I appreciate any help ! ... 9 by: Lloyd Sheen | last post by: For all those who don't think that a recursive search of files in folders is a good thing in the Microsoft.VisualBasic.FileIO.FileSystem namespace listen to this. I am reorg my mp3 collection. ... 3 by: AliRezaGoogle | last post by: Dear Members, I have written a recursive function. It calls itself recursively. It is placed inside a thread. So I can easily suspend and resume the thread to suspend or resume the function as... 0 by: lllomh | last post by: Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{ 2 by: isladogs | last post by: The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central... 0 by: tracyyun | last post by: Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to... 2 by: giovanniandrean | last post by: The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions... 3 by: NeoPa | last post by: Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all... 0 by: isladogs | last post by: The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on... 3 by: nia12 | last post by: Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of... 0 by: NeoPa | last post by: Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it... 4 by: GKJR | last post by: Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.