0

Please can you help me with the following question?

An iterative version of the C++ function TransactionList::getTransactionsForDate is given below. It can be applied to any list of transactions and returns the list of all the transactions for the given date. It only works when the date given is valid.
Write an equivalent recursive version of that function so that it can be used in the same way and produces the same result.

TransactionList TransactionList::getTransactionsForDate( 
                                           const Date& date) const {
    assert ( date.isValid()); 
    TransactionList copyTrl( *this);
    TransactionList tempTrl;
    while ( ! copyTrl.isEmpty() )
    {
        if ( copyTrl.first().getDate() == date)
            tempTrl.addAtEnd( first());
        copyTrl.deleteFirst();
    }
    return tempTrl;
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ShawnCplus
1

Please can you help me with the following question?

An iterative version of the C++ function TransactionList::getTransactionsForDate is given below. It can be applied to any list of transactions and returns the list of all the transactions for the given date. It only works when the date given is valid.
Write an equivalent recursive version of that function so that it can be used in the same way and produces the same result.

I added these tags for you

TransactionList TransactionList::getTransactionsForDate( const Date& date) const {
	assert ( date.isValid()); 
	TransactionList copyTrl( *this);
	TransactionList tempTrl;
	while ( ! copyTrl.isEmpty() )
	{
		if ( copyTrl.first().getDate() == date)
			tempTrl.addAtEnd( first());
		copyTrl.deleteFirst();
	}
	return tempTrl;

}

I'll help you first by saying this isn't your first post, it's your 11th, you should know how to use code tags by now. You should also know that we don't give help to those who don't show effort.

Votes + Comments
It's getting tiresome isn't it?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.