Questions tagged [non-recursive]

non-recursive programming avoids risks of recursion by using iteration instead.

In several programming languages, recursion can lead to out-of-memory problems, using non-recursive approaches can avoid this risk.

120 questions
0
votes
1 answer

In need of advice writing nonrecursive factorial code in assembly

So I'm trying to write a non-recursive of factorial procedure uses loop instruction, that parameter is passed through runtime stack. I also need sequence of instruction in main PROC to invoke factorial procedure. Anybody want help me with this…
user4682346
0
votes
1 answer

Algorithm to print the total sum of all the path

Giving you a binary tree which defined as follows: public class TreeNode { public int val; public TreeNode left, right; public TreeNode(int val) { this.val = val; this.left = this.right = null; } } print the total…
Jie
  • 177
  • 4
  • 17
0
votes
0 answers

Hanoi Towers non-recursive wrong steps

I have to write a program that will solve the hanoi towers. I have 3 columns, A-B-C and all the discs will have to be on the B column as the result. I have to write out the steps that each disc performs and in what order. I tried to write it on my…
Maniak
  • 49
  • 6
0
votes
1 answer

Tower of Hanoi with very specific psuedo code

I'm trying to implement the following psuedo code: place all disks in peg 0 p1 = 0 // Disk 1 is located in peg p1, which is peg 0 Loop { move Disk 1 from peg p1 to peg (p1 + 1) % 3 p1 = (p1 + 1) % 3 // update peg location of Disk 1 p = (p1 + 1) %…
0
votes
0 answers

Module specific includes, CXXFLAGS in non-recursive makefile

I am implementing Non-Recursive Make, using John Graham Cummings example here. I would like to be able to specify specific includes or specific compilation flags, depending on which module I'm compiling. For instance, say I have directories(and…
wizurd
  • 3,541
  • 3
  • 33
  • 50
0
votes
1 answer

How do I non-recursively gather folder sizes and their names? (Powershell)

Basically what I'm trying to do is gather users folder size from their network folder then export that to a .csv, directory structure looks something like this: network:\Department\user...User's-stuff The script I have right now gets the department…
Gawndy
  • 51
  • 1
  • 11
0
votes
3 answers

An iterative binary tree traversal in C++

I am working on creating a non recursive traversal for a binary search tree. I am, however, running into a couple of very odd errors. here is the code for my transverse function: void BinarySearchTree::nrInOrderTraversal(void…
Neko
  • 51
  • 1
  • 1
  • 9
0
votes
2 answers

how to convert binary search tree traversal recursion into non-recursive method in java

Forgive me if its asked before but i couldn't find appropriate answer. I have an major issue in converting binary search tree traversal written with recursive method into non recursive method. kindly help me out. Here is a code using recursive…
0
votes
1 answer

Non-recursive traversal of binary search tree to update size

Forgive me if this has been asked, but I wasn't able to find it while searching.. All of the search results were about traversing through the binary tree as if one was searching for a specific node - thus it would end up going down either left or…
user2872988
0
votes
1 answer

Solaris copy files from multiple directories into a single directory

I have a need to regularly copy files from a specific set of source sub directories (100's of them) into a 'flat" directory structure, i.e. i want all the files from the multiple source directories in a single destination directory. I can't seem to…
user3047191
  • 111
  • 1
  • 1
  • 4
0
votes
1 answer

Converting from decimal to non-decimal and printing(no strings, arrays and recursion)

Need help with a idea of how to convert a decimal number to non-decimal form(any, given by user input) and print it. The limitations are that arrays and strings are not allowed and while I wrote a recursive function for that, I am thinking of a…
Sunspawn
  • 817
  • 1
  • 12
  • 27
0
votes
1 answer

Is there way to use a timer to break out of non recursive code in delphi

I am making a program in Delphi that checks urls to see if they are up. The problem is that this action can take bit of time on some websites. I would like it to give up after about 10 seconds. My question is there a way to stop the check after a…
NicholasSPI
  • 13
  • 1
  • 6
0
votes
1 answer

Permutation without recursion?

I was trying to use a for loop to replace the recursion that I usually use, but I found it's harder than I thought. Can anyone tell me how to do it? Thanks! For example, given a vector of 2, 1, 3. There should be six permutations: 1 2 3 1 3 2 2 1…
Arch1tect
  • 4,128
  • 10
  • 48
  • 69
0
votes
2 answers

Reverse stack in increasing order alternately

What is the most elegant way (less code?) of reversing a stack in increasing order in an alternating manner? (non recursively) EX. 1 2 3 4 5 6 7 8 9 10 1 [3 2] 4 5 6 [10 9 8 7]
herpderp
  • 33
  • 1
  • 5
0
votes
1 answer

How can I get number of leaf nodes in binary tree non-recursively?

I have a practice question that I'm stumped on - to get the number of leaf nodes in a binary tree without using recursion. I've had a bit of a look around for ideas, I've seen some such as passing the nodes to a stack, but I don't see how to do it…
andrewb
  • 5,200
  • 6
  • 36
  • 54