# Turn a recursive Function into a stack base

Page 1 of 1

## 3 Replies - 523 Views - Last Post: 25 March 2011 - 06:46 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=223942&amp;s=0368e3ca43f4f25785a3a52302e985df&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 gbk

Reputation: 0
• Posts: 9
• Joined: 22-March 11

# Turn a recursive Function into a stack base

Posted 23 March 2011 - 05:03 PM

hi i have been asked to turn a recursive function into a stack base but i am not sure what that's mean but i choose the fibonacci recursive function and i turned it into the stack base ?? is this the right way or the right example to answer this question ?
```Public Function fib(ByVal value As Integer) As Integer

Dim x As Stack
x = New Stack(30)
Dim temp As Integer = 1
Dim result As Integer = 0

x.Push(value - 1)
x.Push(value - 2)

While (x.Empty() = False)

temp = x.Pop()

If (temp = 1 Or temp = 0) Then
result = result + temp
Else
x.Push(temp - 1)
x.Push(temp - 2)
End If

End While

Return result

End Function

```

This post has been edited by macosxnerd101: 23 March 2011 - 05:07 PM
Reason for edit:: Please use code tags

Is This A Good Question/Topic? 0

## Replies To: Turn a recursive Function into a stack base

### #2 modi123_1

• Suitor #2

Reputation: 11494
• Posts: 45,367
• Joined: 12-June 08

## Re: Turn a recursive Function into a stack base

Posted 23 March 2011 - 05:46 PM

What do you mean by "stack base"?

this?

Just a heads up if you are not sure about a term or an assignment it pays to ask the teacher for clarification. I mean it is *your* education.

Hit me up with a bit clearer terms!

This post has been edited by modi123_1: 23 March 2011 - 05:46 PM

### #3 gbk

Reputation: 0
• Posts: 9
• Joined: 22-March 11

## Re: Turn a recursive Function into a stack base

Posted 25 March 2011 - 06:12 AM

Thank you for your reply but actually i have not been asked by my teacher , i have interview it will take place after a week from now !! and they told to prepare really well !! one of the thing that i need to know is how to turn e recursive into a stack base no matter what the language that you will use so that's why i am not sure what exactly that's mean

### #4 MrPerq

Reputation: 10
• Posts: 57
• Joined: 01-March 11

## Re: Turn a recursive Function into a stack base

Posted 25 March 2011 - 06:46 AM

Try implementing the QuickSort Algoritm in a single function,
without using recursion. You do this by keeping a list of ranges
you still need to divide, and repeat the algoritm in a while loop
till the list is empty.

This is usually done for increased performance, as recursive algoritms
put a really big pressure on the (Function)Stack.

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}