Recursion- Help to This Newbie

I am trying to learn recursion. It seems easier but I have one problem that I need to learn. I am trying to write function that adds 10 linked list to a list. The code does not work. Can you please help me?

Code:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

struct gemi
{
int armour;
gemi *yeni_gemi;
};



int j = 0;

gemi* gemicogalt(gemi* p_dusman_gemi, int size)
{
j+=1;
gemi *r_gemi = new gemi;
r_gemi->armour = j + 1;
r_gemi->yeni_gemi = p_dusman_gemi;
p_dusman_gemi = r_gemi;
size--;

if (size > 0 )
{

gemicogalt(p_dusman_gemi, size);

}

return r_gemi; //r_gemi;

}

int _tmain(int argc, _TCHAR* argv[])
{
gemi* g_p_dusman_gemi = new gemi;
g_p_dusman_gemi->armour=1;
g_p_dusman_gemi->yeni_gemi=NULL;

g_p_dusman_gemi = gemicogalt(g_p_dusman_gemi, 10);

while(g_p_dusman_gemi != NULL)
{
cout << g_p_dusman_gemi->armour;
g_p_dusman_gemi = g_p_dusman_gemi->yeni_gemi;
}

cin.get();
cin.ignore();

}
Last edited on
Bump
Topic archived. No new replies allowed.