Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pokedex_Assignment
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
a-j.towse
Pokedex_Assignment
Commits
5e278819
Commit
5e278819
authored
Jan 02, 2023
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working ListPokemon function
parent
556f2259
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
main
main
+0
-0
main.c
main.c
+27
-16
No files found.
main
View file @
5e278819
No preview for this file type
main.c
View file @
5e278819
...
...
@@ -74,29 +74,22 @@ struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] ) {
void
AddPokemonToList
(
struct
Pokedex
pokedex
,
char
name
[],
char
type
[],
char
ability
[]){
PokemonNode
*
newNode
=
NewPokemonNode
(
name
,
type
,
ability
);
//Call NewPokemonNode and store ptr to new node in variable
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
PokemonNode
*
temp
=
*
ptrHead
;
//Create temp
variable to store current node in list traversal
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
//Create pointer to pointer variable from pokedex pointer
PokemonNode
*
temp
=
*
ptrHead
;
//Create temp pointer
variable to store current node in list traversal
//check that the node exists first
if
(
newNode
!=
NULL
){
//If the list is empty, point head to new node
if
(
temp
==
NULL
)
{
*
ptrHead
=
newNode
;
//Point the head to the new node
newNode
->
prev
=
NULL
;
//Set the new node prev to NULL
newNode
->
next
=
NULL
;
newNode
->
prev
=
NULL
;
//Set the new node prev to NULL
newNode
->
next
=
NULL
;
//Set the new node next to NULL
return
;
}
while
(
temp
->
next
!=
NULL
)
{
//If pokemon already exists in the list, do nothiing
if
(
strcmp
(
temp
->
name
,
newNode
->
name
)
==
0
)
{
return
;
}
temp
=
temp
->
next
;
printf
(
"%s
\n
"
,
temp
->
name
);
if
(
FindPokemon
(
pokedex
,
newNode
->
name
)
!=
NULL
)
{
//Call FindPokemon to check if the pokemon eixists in the list already
return
;
}
temp
->
next
=
newNode
;
//Set the next pointer of the old last node to new node
...
...
@@ -117,10 +110,20 @@ struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) {
}
temp
=
temp
->
next
;
}
return
NULL
;
}
void
ListPokemon
(
Pokedex
pokedex
)
{
PokemonNode
**
ptrHead
=
pokedex
.
ptrToPokemonHead
;
PokemonNode
*
temp
=
*
ptrHead
;
while
(
temp
!=
NULL
)
{
printf
(
"Name: %s
\n
"
,
temp
->
name
);
temp
=
temp
->
next
;
}
}
int
main
(
void
)
{
...
...
@@ -131,10 +134,18 @@ int main (void) {
pokedex
.
ptrToPlayerHead
=
&
PlayerHead
;
//Set pointer value head of Player List
pokedex
.
ptrToPokemonHead
=
&
PokemonHead
;
//Set pointer value to head of Pokemon List
//NewPokemonNode("Charmander","Fire","FireBallz");
//Tests for function implementation
//NewPokemonNode("Charmander","Fire","FireBallz");
AddPokemonToList
(
pokedex
,
"Charmander"
,
"Fire"
,
"FireBallz"
);
AddPokemonToList
(
pokedex
,
"Squirtle"
,
"Water"
,
"WaterBlast"
);
AddPokemonToList
(
pokedex
,
"Squirtle"
,
"Water"
,
"WaterBlast"
);
//Testing that it doesnt add a duplicate
AddPokemonToList
(
pokedex
,
"The grass one"
,
"Leaf"
,
"LeafSomething"
);
printf
(
"%p
\n
"
,
FindPokemon
(
pokedex
,
"Charmander"
));
ListPokemon
(
pokedex
);
printf
(
"%p
\n
"
,
FindPokemon
(
pokedex
,
"Squirtle"
));
return
0
;
}
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