Commit ed2565c1 authored by a-j.towse's avatar a-j.towse

All commented to date

parent a8969b0a
...@@ -97,31 +97,34 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil ...@@ -97,31 +97,34 @@ void AddPokemonToList(struct Pokedex pokedex,char name[], char type[], char abil
} }
} }
//Create Findpokemon function, returns pointer to the node if found, NULL (nil) if not found
struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) {
struct PokemonNode * FindPokemon(struct Pokedex pokedex, char name[]) { /*Add comments to these two functions*/ 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
PokemonNode **ptrHead = pokedex.ptrToPokemonHead;
PokemonNode *temp = *ptrHead;
//Traverse list with temp until NULL
while (temp != NULL) { while (temp != NULL) {
//string comparison of current node name and target name
if (strcmp(temp->name,name) == 0) { if (strcmp(temp->name,name) == 0) {
return temp; return temp; //If string comparison is true (0) return address of current node
} }
temp = temp->next; temp = temp->next; //temp increments to the next item in the list
} }
return NULL; return NULL;
} }
//Create ListPokemon function, prints a list of pokemon names, returns void
void ListPokemon(Pokedex pokedex) { void ListPokemon(Pokedex pokedex) {
PokemonNode **ptrHead = pokedex.ptrToPokemonHead; PokemonNode **ptrHead = pokedex.ptrToPokemonHead; //Create pointer to pointer variable from pokedex pointer
PokemonNode *temp = *ptrHead; PokemonNode *temp = *ptrHead; //Create temp pointer variable to store current node in list traversal
//Traverse list with temp until NULL
while (temp != NULL) { while (temp != NULL) {
printf("Name: %s\n",temp->name); printf("Name: %s\n",temp->name); //Print the name of the node that temp is currently pointing to
temp = temp->next; temp = temp->next; //temp increments to the next item in the list
} }
} }
...@@ -134,7 +137,7 @@ int main (void) { ...@@ -134,7 +137,7 @@ int main (void) {
pokedex.ptrToPlayerHead = &PlayerHead; //Set pointer value head of Player List pokedex.ptrToPlayerHead = &PlayerHead; //Set pointer value head of Player List
pokedex.ptrToPokemonHead = &PokemonHead; //Set pointer value to head of Pokemon List pokedex.ptrToPokemonHead = &PokemonHead; //Set pointer value to head of Pokemon List
//Tests for function implementation /*Tests for function implementation*/
//NewPokemonNode("Charmander","Fire","FireBallz"); //NewPokemonNode("Charmander","Fire","FireBallz");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment