Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <stdlib.h>
- #include "Pokemon.h"
- /*Função responsável por zerar a bolsa pokemon*/
- void limpaBag(tPokeBag* p) {
- }
- /*Iniciar a bolsa pokemon*/
- void initBag(tPokeBag* p) {
- p->inicio = NULL;
- p->numElem = 0;
- }
- /*Tamanho da bolsa*/
- int tamBag(tPokeBag p) {
- return p.numElem;
- }
- /*Função que imprime na tela os pokemon da bolsa pokemon*/
- void imprimeBag(tPokeBag p) {
- int count;
- if (p.inicio == NULL)
- printf("Bolsa de Pokemon vazia!!\n");
- else {
- printf("Imprimindo a Bolsa Pokemon\n");
- tPokemon* pos = p.inicio;
- while (pos != NULL) {
- printf("Pokemon %d|| CP %d || HP %d \n", pos->ID, pos->cp, pos->hp);
- pos = pos->prox;
- }
- }
- }
- /*Função que insere os pokemon ordenadamente por numero, onde o primeiro de cada numero é o pokemon mais recente*/
- bool insereOrdenadoBag(tPokeBag* p, int valor) {
- tPokemon* novoPoke;
- tPokemon* posAtual;
- novoPoke = (tPokemon*) malloc (sizeof(tPokemon));
- if (novoPoke != NULL) {
- novoPoke->ID = valor;
- novoPoke->cp = rand () % 3000;
- novoPoke->hp = rand () % 500;
- if (p->inicio == NULL) {
- novoPoke->prox = NULL;
- p->inicio = novoPoke;
- }
- else if (valor < p->inicio->ID || valor == p->inicio->ID) {
- novoPoke->prox = p->inicio;
- p->inicio->ant = novoPoke;
- p->inicio = novoPoke;
- }
- else {
- posAtual = p->inicio;
- while (posAtual->prox != NULL && posAtual->prox->ID < valor)
- posAtual = posAtual->prox;
- novoPoke->prox = posAtual->prox;
- novoPoke->ant = posAtual;
- if (posAtual->prox != NULL)
- posAtual->prox->ant = novoPoke;
- posAtual->prox = novoPoke;
- }
- p->numElem++;
- printf("Pokemon adicionado corretamente na Bolsa\n");
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment