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
8916b496
Commit
8916b496
authored
Jan 02, 2023
by
a-j.towse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
half working addToList
parent
9d1811c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
14 deletions
+50
-14
main
main
+0
-0
main.c
main.c
+50
-14
No files found.
main
View file @
8916b496
No preview for this file type
main.c
View file @
8916b496
...
@@ -10,8 +10,8 @@ A-J Towse
...
@@ -10,8 +10,8 @@ A-J Towse
//Create struct Pokedex with a pointer to head of Pokemon and head of Player
//Create struct Pokedex with a pointer to head of Pokemon and head of Player
typedef
struct
Pokedex
{
typedef
struct
Pokedex
{
struct
PokemonNode
*
ptrToPokemonh
ead
;
struct
PokemonNode
*
*
ptrToPokemonH
ead
;
struct
PlayerNode
*
ptrToPlayerh
ead
;
struct
PlayerNode
*
*
ptrToPlayerH
ead
;
}
Pokedex
;
}
Pokedex
;
//Create struct PokemonNode with name,type,ability variables
//Create struct PokemonNode with name,type,ability variables
...
@@ -36,15 +36,10 @@ typedef struct PlayerNode {
...
@@ -36,15 +36,10 @@ typedef struct PlayerNode {
struct
PokemonNode
pokemonList
[];
struct
PokemonNode
pokemonList
[];
}
PlayerNode
;
}
PlayerNode
;
PokemonNode
*
head
=
NULL
;
//Create head for DLL of pokemon
PlayerNode
*
head
=
NULL
;
//Create head for DLL of players
//NEED TO CREATE VARIABLE OF TYPE POKEDEX
//Define functions for PokemonNode struct
//Define functions for PokemonNode struct
struct
PokemonNode
*
NewPokemonNode
(
char
name
[],
char
type
[],
char
ability
[]
);
struct
PokemonNode
*
NewPokemonNode
(
char
name
[],
char
type
[],
char
ability
[]
);
void
AddPokemonToList
(
struct
Pokedex
*
pokedex
,
char
name
[],
char
type
[],
char
ability
[]);
void
AddPokemonToList
(
struct
Pokedex
pokedex
,
char
name
[],
char
type
[],
char
ability
[]);
struct
PokemonNode
*
FindPokemon
(
struct
Pokedex
pokedex
,
char
name
);
struct
PokemonNode
*
FindPokemon
(
struct
Pokedex
pokedex
,
char
name
[]
);
//Define functions for PlayerNode struct
//Define functions for PlayerNode struct
struct
PlayerNode
*
NewPlayerNode
(
char
name
);
struct
PlayerNode
*
NewPlayerNode
(
char
name
);
...
@@ -76,24 +71,65 @@ struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] ) {
...
@@ -76,24 +71,65 @@ struct PokemonNode * NewPokemonNode(char name[], char type[], char ability[] ) {
}
}
//Create AddPokemonToList function - returns void
//Create AddPokemonToList function - returns void
void
AddPokemonToList
(
struct
Pokedex
*
pokedex
,
char
name
[],
char
type
[],
char
ability
[]){
void
AddPokemonToList
(
struct
Pokedex
pokedex
,
char
name
[],
char
type
[],
char
ability
[]){
NewPokemonNode
(
name
,
type
,
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
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
;
return
;
}
/*while (temp->next != NULL) {
//If pokemon already exists in the list, do nothiing
if (strcmp(temp->name,newNode->name) == 0) {
return;
}
}*/
temp
->
next
=
newNode
;
//Set the next pointer of the old last node to new node
newNode
->
prev
=
temp
;
//Set the prev pointer of the new node to the old last node
}
}
}
struct
PokemonNode
*
FindPokemon
(
struct
Pokedex
pokedex
,
char
name
[])
{
PokemonNode
*
temp
=
pokedex
.
ptrToPokemonHead
;
while
(
temp
->
next
!=
NULL
)
{
if
(
strcmp
(
temp
->
name
,
name
)
==
0
)
{
return
temp
;
}
}
}
int
main
(
void
)
{
int
main
(
void
)
{
PokemonNode
*
PokemonHead
=
NULL
;
//Create head for DLL of pokemon
PlayerNode
*
PlayerHead
=
NULL
;
//Create head for DLL of players
Pokedex
pokedex
;
//Create a pointer to a Pokedex structure, NULL
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");
//NewPokemonNode("Charmander","Fire","FireBallz");
AddPokemonToList
(
pokedex
,
"Charmander"
,
"Fire"
,
"FireBallz"
);
AddPokemonToList
(
pokedex
,
"Charmander"
,
"Fire"
,
"FireBallz"
);
AddPokemonToList
(
pokedex
,
"Squirtle"
,
"Water"
,
"WaterBlast"
);
//printf("%p\n",FindPokemon(pokedex,"Charmander"));
return
0
;
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