Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Recursion

Name: Anonymous 2009-03-08 4:33

the most widely-acclaimed recursion algorithm ever:

yo dawg i heard you like cars so we put a car in your car so you can drive while you drive

don't deny it /prog/. it is ingenious.

Name: Anonymous 2009-03-08 4:43

NO EXCEPTIONS

Name: Anonymous 2009-03-08 4:56

but i cant read what you're saying

Name: Anonymous 2009-03-08 5:06

>>1
No cudders? You fail.

Name: Anonymous 2009-03-08 6:06


#include <list>

struct car {
    car() : car_(0) {}
    car* car_;
};

void yo_dawg(car* in, int depth)
{
    if(depth == 2)
        return;
    in->car_ = new car;
}

void yo_dawg(car* in)
{
    std::list<car*> cars;
    while(in->car_)
    {
        cars.push_back(in);
        in = in->car_;
    }
    std::list<car*>::reverse_iterator iter;
    for(iter = cars.rbegin(); iter != cars.rend(); ++iter)
        delete *iter;
}

int main(int argc, char* argv[])
{
    car* car_ = new car;
    yo_dawg(car_, 1);
    yo_dawg(car_);
}

Name: Anonymous 2009-03-08 6:40

>>5
Well, then

Name: Anonymous 2009-03-08 17:20

>>5


void yo_dawg(car* in, int depth)
{
    if(depth == 2)
        return;
    in->car_ = new car;
    yo_dawg(in->car_, depth + 1);
}


fixd

Name: Anonymous 2010-12-17 1:36

Erika once told me that Xarn is a bad boyfriend

Name: Anonymous 2010-12-26 4:07

Name: Anonymous 2011-01-31 19:51

<-- check em dubz

Don't change these.
Name: Email:
Entire Thread Thread List