-2
Guys I’m not getting to develop this function.
bool inserir_fim (tipo_lista * p, tipo_lista * novo_no)
{
}
-2
Guys I’m not getting to develop this function.
bool inserir_fim (tipo_lista * p, tipo_lista * novo_no)
{
}
1
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
struct tipo_lista{
int info;
struct tipo_lista * prox;
};
typedef struct tipo_lista tipo_lista;
tipo_lista * cria_no (int valor)
{
tipo_lista * novo;
novo = (tipo_lista *)malloc(sizeof(tipo_lista));
novo -> info = valor;
novo -> prox = NULL;
return novo;
}
bool inserir_fim (tipo_lista * p, tipo_lista * novo_no)
{
if (!p) {
return false;
}
while (p->prox) {
p = p->prox;
}
p->prox = novo_no;
return true;
}
int main(void) {
tipo_lista * p = cria_no(1);
inserir_fim(p, cria_no(2));
printf("%d %d\n", p->info, p->prox->info);
return 0;
}
It would not be true or false return?
I think so, maybe 0 and 1 works, but it’s better true and false.
And how I test it on main?
You will need the function to create a new node to test this function.
type: https://pastebin.com/vyGn1mJm
I edited the answer with the main.
error on this main printf
What error did you make? I am testing here: https://ideone.com/6h1WsX
Let’s go continue this discussion in chat.
Browser other questions tagged c
You are not signed in. Login or sign up in order to post.
You have examples here: http://www.cprogressivo.net/2013/10/Lista-simplesmentente_chainedto a hair_com-C-Inserindo-nos-no-inicio-e-fim.html
– Jessika