Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Double Linked List - Programação 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leonardo Krambeck
Double Linked List - Programação 1
Commits
089ff3f2
Commit
089ff3f2
authored
5 years ago
by
Leonardo Krambeck
Browse files
Options
Downloads
Patches
Plain Diff
implementa insere ordenado
parent
f1ef5480
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib_lista.c
+54
-20
54 additions, 20 deletions
lib_lista.c
main.c
+21
-8
21 additions, 8 deletions
main.c
with
75 additions
and
28 deletions
lib_lista.c
+
54
−
20
View file @
089ff3f2
...
...
@@ -9,7 +9,6 @@ int inicializa_lista(t_lista *l)
/* Insert beginning sentinel */
sentinel
=
(
t_nodo
*
)
malloc
(
sizeof
(
t_nodo
));
if
(
sentinel
==
NULL
)
return
0
;
...
...
@@ -18,7 +17,6 @@ int inicializa_lista(t_lista *l)
/* Insert end sentinel */
sentinel
=
(
t_nodo
*
)
malloc
(
sizeof
(
t_nodo
));
if
(
sentinel
==
NULL
)
return
0
;
...
...
@@ -60,10 +58,18 @@ void destroi_lista(t_lista *l)
l
->
tamanho
=
0
;
}
int
tamanho_lista
(
int
*
tam
,
t_lista
*
l
)
{
if
(
l
->
ini
==
NULL
&&
l
->
fim
==
NULL
)
return
0
;
*
tam
=
l
->
tamanho
;
return
1
;
}
int
insere_inicio_lista
(
int
item
,
t_lista
*
l
)
{
t_nodo
*
new
;
new
=
(
t_nodo
*
)
malloc
(
sizeof
(
t_nodo
));
if
(
new
==
NULL
)
return
0
;
...
...
@@ -80,19 +86,9 @@ int insere_inicio_lista(int item, t_lista *l)
return
1
;
}
int
tamanho_lista
(
int
*
tam
,
t_lista
*
l
)
{
if
(
l
->
ini
==
NULL
&&
l
->
fim
==
NULL
)
return
0
;
*
tam
=
l
->
tamanho
;
return
1
;
}
int
insere_fim_lista
(
int
item
,
t_lista
*
l
)
{
t_nodo
*
new
;
new
=
(
t_nodo
*
)
malloc
(
sizeof
(
t_nodo
));
if
(
new
==
NULL
)
return
0
;
...
...
@@ -109,18 +105,56 @@ int insere_fim_lista(int item, t_lista *l)
return
1
;
}
/*
Insere o elemento item na lista de maneira que ela fique em ordem
crescente, do início para o final dela.
Retorna 1 se a operação foi bem sucedida e zero caso contrário.
*/
int
insere_ordenado_lista
(
int
item
,
t_lista
*
l
){
return
1
;}
int
insere_ordenado_lista
(
int
item
,
t_lista
*
l
)
{
if
(
lista_vazia
(
l
))
return
insere_inicio_lista
(
item
,
l
);
t_nodo
*
new
;
new
=
(
t_nodo
*
)
malloc
(
sizeof
(
t_nodo
));
if
(
new
==
NULL
)
return
0
;
new
->
chave
=
item
;
t_nodo
*
p
=
l
->
ini
->
prox
;
while
(
p
->
prox
!=
NULL
&&
p
->
chave
<
item
)
p
=
p
->
prox
;
new
->
prox
=
p
;
new
->
prev
=
p
->
prev
;
p
->
prev
->
prox
=
new
;
p
->
prev
=
new
;
l
->
tamanho
++
;
return
1
;
}
/*
Remove o primeiro elemento da lista e o retorna em *item.
Retorna 1 se a operação foi bem sucedida e zero caso contrário.
*/
int
remove_inicio_lista
(
int
*
item
,
t_lista
*
l
){
return
1
;}
int
remove_inicio_lista
(
int
*
item
,
t_lista
*
l
)
{
if
(
lista_vazia
(
l
))
{
item
=
NULL
return
0
;
}
t_nodo
*
p
=
l
->
ini
->
prox
;
l
->
ini
=
p
->
prox
;
p
->
prox
->
prev
=
l
->
ini
free
(
p
);
l
->
tamanho
--
;
return
1
;
}
/*
Remove o último elemento da lista e o retorna em *item.
...
...
This diff is collapsed.
Click to expand it.
main.c
+
21
−
8
View file @
089ff3f2
...
...
@@ -2,19 +2,32 @@
#include
"lib_lista.h"
void
imprime
(
t_lista
*
l
)
{
t_nodo
*
p
=
l
->
ini
->
prox
;
while
(
p
->
prox
->
prox
!=
NULL
)
{
printf
(
"%d "
,
p
->
chave
);
p
=
p
->
prox
;
}
printf
(
"%d
\n
"
,
p
->
chave
);
}
int
main
()
{
t_lista
l
;
int
tam
;
inicializa_lista
(
&
l
);
insere_inicio_lista
(
10
,
&
l
);
insere_inicio_lista
(
5
,
&
l
);
tamanho_lista
(
&
tam
,
&
l
);
printf
(
"tam: %d
\n
"
,
tam
);
insere_fim_lista
(
8
,
&
l
);
tamanho_lista
(
&
tam
,
&
l
);
printf
(
"tam: %d
\n
"
,
tam
);
insere_ordenado_lista
(
7
,
&
l
);
insere_ordenado_lista
(
10
,
&
l
);
insere_ordenado_lista
(
1
,
&
l
);
insere_ordenado_lista
(
3
,
&
l
);
insere_ordenado_lista
(
2
,
&
l
);
imprime
(
&
l
);
remove_inicio_lista
(
&
l
);
imprime
(
&
l
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment