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

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 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_);
}

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