Skip to content

Commit 7538394

Browse files
committed
fazendo linked_list
1 parent c239dca commit 7538394

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Repositório com os programas e algoritmos que criei durante o curso de Estrutura de Dados, modo remoto :)
1+
Repositório com os programas e algoritmos que implementei durante o curso de Estrutura de Dados, modo remoto :)

linked_list.c

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
/*
5+
L in k e d L i s t . h
6+
TAD para r e p r e s e n t a r uma L i s t a Encadeada .
7+
*/
8+
typedef struct node{ // define o tipo nó;
9+
int item;
10+
void *next;
11+
}Node; //o apelido desse tipo é Node
12+
13+
Node* createLinkedList()
14+
{
15+
return NULL;//pq tem que ser null????
16+
}
17+
18+
int isEmpty( Node *head)
19+
{
20+
return (head == NULL);
21+
}
22+
23+
/*
24+
malloc retorna um endereço de um espaço de memória alocado
25+
ponteiro é um referenciador, se ele não for inicializado, ele aponta para qualquer lugar
26+
quando eu crio um novo ponteiro, ele precisa de um lugar para apontar
27+
se um faço um ponteiro que nao aponta pra lugar nenhum.... memory leak
28+
(Node*) malloc(sizeof(Node)) é um endereço para tipo Node
29+
*/
30+
31+
Node* insertNode (Node *head, int item) //insere um nó na cabeça
32+
{
33+
Node* new_node = (Node*) malloc(sizeof(Node)); //crio um novo ponteiro(endereço do tipo Node) com o nome de new_node... esse endereço é igual a outro endereço
34+
new_node->item = item;
35+
new_node->next = head;
36+
return new_node; //aqui new_node para de existir
37+
}
38+
39+
void printLinkedList(Node *head)
40+
{
41+
while (isEmpty(head) != 1)
42+
{
43+
printf("%d\n", head->item);
44+
head = head->next;
45+
}
46+
return;
47+
}
48+
49+
Node* search(Node *head, int item)
50+
{
51+
while (head != NULL)
52+
{
53+
if (head->item == item)
54+
{
55+
return head;
56+
}
57+
head = head->next;
58+
}
59+
return NULL;
60+
}
61+
62+
Node* removeNode(Node *head, int item)
63+
{
64+
Node* itemplace = search(head,item);
65+
/*int* x;//cria ponteiro para int
66+
*x;//pega o valor do ponteiro para int */
67+
68+
69+
70+
}
71+
72+
73+
74+
75+
76+
77+
78+
Node* search(Node *head, int item) ;
79+
Node* removeNode( Node *head, int item) ;
80+
81+
82+
83+
int main()
84+
{
85+
86+
Node* lista1 = createLinkedList();
87+
88+
89+
/* insertNode(Node *head , int item );
90+
void printLinkedList( Node *head );
91+
int isEmpty (Node *head );
92+
search(Node *head , int item );
93+
removeNode( Node *head , int item ); */
94+
}

0 commit comments

Comments
 (0)