Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lab0test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Lars Öberg
Lab0test
Commits
d66c0455
Commit
d66c0455
authored
4 years ago
by
Max Skanvik
Browse files
Options
Downloads
Patches
Plain Diff
finished part 3 with no memory leaks
parent
c14de348
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
linked_list.c
+32
-6
32 additions, 6 deletions
linked_list.c
ll
+0
-0
0 additions, 0 deletions
ll
with
32 additions
and
6 deletions
linked_list.c
+
32
−
6
View file @
d66c0455
...
...
@@ -2,6 +2,7 @@
#include
<stdio.h>
#include
<stdlib.h>
struct
list_item
{
int
value
;
struct
list_item
*
next
;
...
...
@@ -19,20 +20,30 @@ void append(struct list_item *first, int x){
current
->
next
=
new_item
;
}
void
prepend
(
struct
list_item
*
first
,
int
x
){
struct
list_item
*
new_item
=
(
struct
list_item
*
)
malloc
(
sizeof
(
struct
list_item
));
new_item
->
next
=
first
;
new_item
->
next
=
first
->
next
;
new_item
->
value
=
x
;
first
->
next
=
new_item
;
}
void
print
(
struct
list_item
*
first
){
struct
list_item
*
current
=
first
;
while
(
current
->
next
!=
NULL
)
{
current
=
current
->
next
;
printf
(
"%d
\n
"
,
current
->
value
);
if
(
current
->
next
!=
NULL
)
{
while
(
current
->
next
!=
NULL
)
{
current
=
current
->
next
;
printf
(
"%d
\n
"
,
current
->
value
);
}
}
else
{
printf
(
"Empty arry
\n
"
);
}
printf
(
"
\n
"
);
}
void
input_sorted
(
struct
list_item
*
first
,
int
x
){
struct
list_item
*
current
=
first
;
while
((
current
->
next
!=
NULL
)
&&
(
current
->
next
->
value
<
x
))
{
...
...
@@ -44,15 +55,17 @@ void input_sorted(struct list_item *first, int x){
current
->
next
=
new_item
;
}
void
clear
(
struct
list_item
*
first
){
struct
list_item
*
current
;
while
(
first
->
next
!=
NULL
)
{
current
=
first
;
first
=
current
->
next
;
current
=
first
->
next
;
first
->
next
=
current
->
next
;
free
(
current
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
struct
list_item
root
;
...
...
@@ -64,6 +77,19 @@ int main(int argc, char ** argv)
input_sorted
(
&
root
,
4
);
input_sorted
(
&
root
,
3
);
input_sorted
(
&
root
,
1
);
// print(&root);
append
(
&
root
,
16
);
append
(
&
root
,
17
);
append
(
&
root
,
16
);
// print(&root);
prepend
(
&
root
,
22
);
prepend
(
&
root
,
21
);
prepend
(
&
root
,
20
);
clear
(
&
root
);
print
(
&
root
);
return
0
;
}
This diff is collapsed.
Click to expand it.
ll
0 → 100755
+
0
−
0
View file @
d66c0455
File added
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