![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Newbie
Join Date: Apr 2006
Posts: 5
Rep Power: 0
![]() |
Recursion
I'm studying programming theory at the moment, and one of the questions on my next assignment is about recursion. I have to check if a vector is sorted and return true.
The function returns true if the vector is empty and also returns true if the vector has length = 1. I need to do the check recursively, any pointers in the right direction. Quote:
Any pointers in the right direction would be appreciated. |
|
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Have the function divide the vector into two and call itself for each half. We won't write the code for you. If you decide to post code or ask for additional help, be sure and read the forum's FAQ/rules first.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2006
Posts: 5
Rep Power: 0
![]() |
Thanks for the pointer. I don't want the code written for me, ain't gonna learn much that way, just need a different way to look at the problem, which I think you may have provided for me. Thanks for the help
Starrboy |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2006
Posts: 5
Rep Power: 0
![]() |
Sorted it out. Just had to check if the penultimate value in the vector was greater than the last value in the vector, then knock of the last value in the vector and use this as the argument when the function calls itself.
Starrboy |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|