473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2527
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 <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> 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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.