Function insert in list

Asked

Viewed 68 times

1

Hello. I am developing this function below:

void inserir_inicio (tipo_lista * p, tipo_lista * novo_no)
{
  novo_no -> prox = p;
  p = novo_no;
}

And in the main I’m calling for:

inserir_inicio(&p, cria_no(1));
imprimir_lista(p);

And when I run nothing comes out on the screen.

Would someone tell me if the in_start function is wrong?

1 answer

3


In main your function starts empty(NULL), then you call the insert function and do not update the main value, then the list remains empty. If the list is not empty, you will insert at the beginning and will not update at the main which is the first, then the error continues.

What is missing is the Return:

tipo_lista * inserir_inicio (tipo_lista * p, tipo_lista * novo_no)
{
  novo_no -> prox = p;
  return novo_no;
}

And in main:

p = inserir_inicio(p, cria_no(1));
imprimir_lista(p);
  • So I want to test with void

  • And with that & gave Program error stopped working.

  • 1

    Why you want to test with void?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.