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
0b8a11f3
Commit
0b8a11f3
authored
Nov 01, 2022
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inital commit
parent
ed422a72
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
3 deletions
+51
-3
main
main
+0
-0
main.c
main.c
+51
-3
No files found.
main
100644 → 100755
View file @
0b8a11f3
No preview for this file type
main.c
View file @
0b8a11f3
...
@@ -13,15 +13,24 @@ node* NewNode(int value);
...
@@ -13,15 +13,24 @@ node* NewNode(int value);
void
AddNodeToStartOfList
(
node
**
ptr_to_start
,
int
value
);
void
AddNodeToStartOfList
(
node
**
ptr_to_start
,
int
value
);
void
AddNodeToEndOfList
(
node
**
ptr_to_start
,
int
value
);
void
AddNodeToEndOfList
(
node
**
ptr_to_start
,
int
value
);
void
PrintLinkedList
(
node
*
start
);
void
PrintLinkedList
(
node
*
start
);
int
ListLength
(
node
*
start
);
void
AddNode
(
node
**
ptr_to_start
,
int
value
);
int
main
(
void
)
{
int
main
(
void
)
{
node
*
head
=
NULL
;
node
*
head
=
NULL
;
AddNodeToStartOfList
(
&
head
,
5
);
AddNodeToStartOfList
(
&
head
,
2
);
AddNodeToEndOfList
(
&
head
,
7
);
AddNodeToEndOfList
(
&
head
,
4
);
AddNodeToEndOfList
(
&
head
,
2
);
AddNodeToEndOfList
(
&
head
,
6
);
PrintLinkedList
(
head
);
PrintLinkedList
(
head
);
printf
(
"List Length: %d
\n
"
,
ListLength
(
head
));
AddNode
(
&
head
,
5
);
printf
(
"List Length: %d
\n
"
,
ListLength
(
head
));
return
0
;
return
0
;
}
}
...
@@ -91,6 +100,45 @@ void AddNodeToEndOfList(node **ptr_to_start, int value)
...
@@ -91,6 +100,45 @@ void AddNodeToEndOfList(node **ptr_to_start, int value)
return
;
return
;
}
}
int
ListLength
(
node
*
start
)
{
int
count
=
0
;
while
(
start
!=
NULL
)
{
count
+=
1
;
start
=
start
->
next
;
}
return
count
;
}
void
AddNode
(
node
**
ptr_to_start
,
int
value
)
{
node
*
temp
=
*
ptr_to_start
;
node
*
before
;
node
*
after
;
if
(
temp
==
NULL
)
{
AddNodeToStartOfList
(
ptr_to_start
,
value
);
}
else
{
while
(
temp
!=
NULL
)
{
if
(
temp
->
val
>
value
&&
temp
->
val
<
temp
->
next
->
val
){
before
=
temp
;
after
=
temp
->
next
;
temp
=
NewNode
(
value
);
before
->
next
=
temp
;
temp
->
next
=
after
;
}
else
if
(
temp
->
next
==
NULL
){
AddNodeToEndOfList
(
ptr_to_start
,
value
);
}
else
{
temp
=
temp
->
next
;
}
}
}
}
/* Exercise Tasks
/* Exercise Tasks
1. Write a function int ListLength(*start) which traverses the list, counts the number of nodes and returns that count.
1. Write a function int ListLength(*start) which traverses the list, counts the number of nodes and returns that count.
...
...
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