Advertisement
Guest User

Untitled

a guest
May 24th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cstdlib>
  3. #include "fila.h"
  4.  
  5. Node::Node() {
  6.  
  7. }
  8.  
  9. Node::Node(int valor) {
  10. this->valor = valor;
  11. this->prox = NULL;
  12. }
  13.  
  14. void Node::setValor(int valor) {
  15. this->valor = valor;
  16. }
  17.  
  18. void Node::setProx(Node* prox) {
  19. this->prox = prox;
  20. }
  21.  
  22. int Node::getValor() {
  23. return this->valor;
  24. }
  25.  
  26. Node* Node::getProx() {
  27. return this->prox;
  28. }
  29.  
  30. Fila::Fila() {
  31. this->tamanho = 0;
  32. }
  33.  
  34. void Fila::enfileirar(int valor) {
  35. if (this->tamanho == 0) {
  36. this->primeiro = new Node(valor);
  37. this->ultimo = this->primeiro;
  38. this->tamanho++;
  39. }
  40. else {
  41. this->ultimo->setProx(new Node(valor));
  42. this->ultimo = this->ultimo->getProx();
  43. this->tamanho++;
  44. }
  45.  
  46.  
  47. }
  48.  
  49. int Fila::desenfileirar() {
  50. int valor;
  51. Node* aux;
  52.  
  53. valor = -1;
  54.  
  55. if (this->tamanho == 0) {
  56. printf("Fila vazia!\n");
  57. return -1;
  58. }
  59. else {
  60. valor = this->primeiro->getValor();
  61. aux = this->primeiro;
  62. this->primeiro = this->primeiro->getProx();
  63. delete aux;
  64. this->tamanho--;
  65. return valor;
  66. }
  67. return -1;
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement