void printScientificNotation(double value, int powerOfTen)
{
if (value >= 1.0 && value < 10.0)
{
System.out.println(value + " x 10^" + powerOfTen);
}
else if (value < 1.0)
{
printScientificNotation(value * 10, powerOfTen - 1);
}
else // value >= 10.0
{
printScientificNotation(value / 10, powerOfTen + 1);
}
}
assuming...
Greetings all,
I've written software in the past that uses a stack to check for balanced equations, but now I'm asked to write a similar algorithm recursively to check for properly nested brackets and parenthesis.
Good examples: () [] ()
([]()[])
Bad examples: ( (] ([)]
Suppose my function is called: isBalanced.
Should e...
I use Python multithread to realize Quicksort.
Quicksort is implement in a function. It is a recursive function.
Each thread calls Quicksort to sort the array it has. Each thread has its own array that stores the numbers needs to be sorted.
If the array size is smaller (<10,000). It runs ok.
However, if the array size is larger, it shows...
Hi guys,
I feel a little dumb asking this, but here we go...
When trying to follow the Recursion example at the following website http://www.cplusplus.com/doc/tutorial/functions2/, I ran into a road bump that has me perplexed.
I altered the code slightly just to get my head around the code in the recursion example and I pretty much h...
I have the following:
for (var i = 0; i < children.length; i++){
if(hasClass(children[i], "lbExclude")){
children[i].parentNode.removeChild(children[i]);
}
};
I would like it to loop through all children's children, etc (not just the top level). I found this line, which seems to do that:
for(var m = n.firstChild; m != nu...
I would like to go from one number to another. For example if I started at 6 and my goal was 10 I want a function that on every pass would bring me from 6 towards 10 or if I had the number 14 and my goal was 9 it would count down from 14 towards 9.So far I have (this is written in Processing a Java Api but there is essentially no differe...
I've been using PDO and preparing all my statements primarily for security reasons. However, I have a part of my code that does execute the same statement many times with different parameters, and I thought this would be where the prepared statements really shine. But they actually break the code...
The basic logic of the code is this.
...
I have a backup directory created by WDBackup (western digital external HD backup util) that contains a directory for each day that it backed up and the incremental contents of just what was backed up.
So the hierarchy looks like this:
20100101
My Documents
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My...
Using jQuery, I've build an image/slide rotator. The basic setup is (in pseudocode):
function setupUpSlide(SlideToStartWith){
var thisSlide = SlideToStartWith;
...set things up...
fadeInSlide(thisSlide)
}
function fadeInSlide(thisSlide){
...fade in this slide...
fadeOutSlide(thisSlide)
}
function fadeOutSlide(this...
I need to to write a method that is called like printTriangle(5);. We need to create an iterative method and a recursive method (without ANY iteration). The output needs to look like this:
*
**
***
****
*****
This code works with the iterative but I can't adapt it to be recursive.
public void printTriangle (int count) {
int line ...
I have the following function to sort an unordered array to having even numbers in the front and odd numbers in the back. Is there a way to get it done without using any loops?
//front is 0, back =array.length-1;
arrangeArray (front, back);
public static void arrangeArray (int front, int back)
{
if (front != back || front<back)
...
It's always bugged me a recursive function needs to name itself, when a instantiated class can use $this and a static method can use self etc.
Is there a similar way to do this in a recursive function without naming it again (just to cut down on maintenance)?
Obviously I could use call_user_func or the __FUNCTION__ constant but I would...
Are there any example for a recursive function that call an other one which calls the first one too ?
example
function1()
{
//do something
f2();
//do something
}
function2()
{
//do something
f1();
//do something
}
...
I'm attempting to create a text-based version of this game:
http://www.cse.nd.edu/java/SameGame.html
Here is the code I have so far:
#include <iostream>
#include <vector>
#include <ctime>
class Clickomania
{
public:
Clickomania();
std::vector<std::vector<int> > board;
int move(int, int);
bool isSolv...
String[] dictionary = new String[dictSize]; //arrray of strings from dictionary
String[] tree = new String[3*dictSize]; //array of tree
void makeBST() {
recMakeBST(0, dictionary.length-1);
}//makeBST()
int a=0;
void recMakeBST(int low, int high) {
if(high-low==0){
return;
}
else{
int mid=(high-low)/2;
...
I have files which contain file names pointing to other files. These files contain further file names pointing further files and so on. I need a bash script which follows each files recursively and logs into file every touched file during the run.
file1:
file2
file3
file2:
file4
file3:
file5
file4 and file5 are empty.
Re...
There are tons of examples of using the RecursiveIterator to flatten a tree structure.. but what about using it to explode a tree structure?
Is there an elegant way to use this, or some other SPL library to recursively build a tree (read: turn a flat array into array of arbitrary depth) given a table like this:
SELECT id, parent_id, na...
hi there!
what's the best practise to break a loop?
my ideas were:
Child Find(Parent parent, object criteria)
{
Child child = null;
foreach(Child wannabe in parent.Childs)
{
if (wannabe.Match(criteria))
{
child = wannabe;
}
else
{
child = Find(wannabe, criteri...
Why do I get a segmentation fault in my recursive function. It happens every time i call it when a value greater than 4 as a parameter
#include <iostream>
#include <limits>
using namespace std;
int printSeries(int n){
if(n==1){
return 1;
}
else if( n==2){
return 2;
}
else if( n==3){
...
Suppose a tree structure is implemented in SQL like this:
CREATE TABLE nodes (
id INTEGER PRIMARY KEY,
parent INTEGER -- references nodes(id)
);
Although cycles can be created in this representation, let's assume we never let that happen. The table will only store a collection of roots (records where parent is null) and their...