Skip to content

Commit 3c8f42e

Browse files
committed
feat: added example
1 parent fb1e59e commit 3c8f42e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
6+
typedef struct no{
7+
char nome_fruta[20];
8+
struct no * proxima;
9+
}No;
10+
11+
No * adiciona_fruta(No * lista, char * nome_fruta){
12+
No * nova_fruta = (No*) malloc(sizeof(No));
13+
if (nova_fruta==NULL){
14+
printf("No memory!\n");
15+
exit(1);
16+
}
17+
strcpy(nova_fruta->nome_fruta,nome_fruta);
18+
nova_fruta->proxima=lista;
19+
return nova_fruta;
20+
}
21+
22+
void imprime_Lista_frutas(No * lista){
23+
No * contador;
24+
for(contador=lista; contador!=NULL; contador=contador->proxima){
25+
printf(" %s -> ", contador->nome_fruta);
26+
}
27+
}
28+
29+
int main(void){
30+
No * lista_de_frutas;
31+
lista_de_frutas = NULL;
32+
lista_de_frutas = adiciona_fruta(lista_de_frutas, "Morango");
33+
lista_de_frutas = adiciona_fruta(lista_de_frutas, "Abacate");
34+
lista_de_frutas = adiciona_fruta(lista_de_frutas, "Goiaba");
35+
imprime_Lista_frutas(lista_de_frutas);
36+
printf("Null");
37+
return 0;
38+
}

root/listas/pratica-01/main

16.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)