Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Excercise 1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Prog03 C
Excercise 1
Commits
5d74f043
Commit
5d74f043
authored
Nov 07, 2022
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working NewNode function
parent
4f92faac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
18 deletions
+38
-18
main
main
+0
-0
main.c
main.c
+38
-18
No files found.
main
View file @
5d74f043
No preview for this file type
main.c
View file @
5d74f043
...
@@ -30,7 +30,7 @@ int main(void) {
...
@@ -30,7 +30,7 @@ int main(void) {
AddNode
(
&
head
,
5
);
AddNode
(
&
head
,
5
);
printf
(
"List Length: %d
\n
"
,
ListLength
(
head
)
);
PrintLinkedList
(
head
);
return
0
;
return
0
;
}
}
...
@@ -112,31 +112,51 @@ int ListLength(node *start) {
...
@@ -112,31 +112,51 @@ int ListLength(node *start) {
void
AddNode
(
node
**
ptr_to_start
,
int
value
)
{
void
AddNode
(
node
**
ptr_to_start
,
int
value
)
{
node
*
temp
=
*
ptr_to_start
;
node
*
current
=
*
ptr_to_start
;
node
*
new_node
=
NewNode
(
value
);
node
*
new_node
=
NewNode
(
value
);
node
*
before
;
node
*
after
;
if
(
*
ptr_to_start
==
NULL
)
{
// special case if the list is empty
if
(
*
ptr_to_start
==
NULL
)
// special case if the list is empty
{
*
ptr_to_start
=
new_node
;
*
ptr_to_start
=
new_node
;
return
;
return
;
}
}
while
(
temp
->
next
!=
NULL
&&
temp
->
next
->
val
<
value
)
{
while
(
current
!=
NULL
)
{
if
(
current
->
next
->
val
>
value
)
{
if
(
ptr_to_start
==
current
)
//if it is smaller than the first value, add to start
{
AddNodeToStartOfList
(
ptr_to_start
,
value
);
return
;
}
if
(
ptr_to_start
==
temp
)
{
else
if
(
current
->
next
==
NULL
)
//if it hits the end of the list/ add to end
AddNodeToStartOfList
(
value
);
{
AddNodeToEndOfList
(
ptr_to_start
,
value
);
return
;
return
;
}
}
else
{
else
temp
=
temp
->
next
;
{
node
*
temp
=
current
->
next
;
current
->
next
=
new_node
;
new_node
->
next
=
temp
;
return
;
}
}
}
else
{
current
=
current
->
next
;
}
}
}
NewNode
(
value
);
}
temp
->
next
=
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment