Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cstdlib>
- #include "fila.h"
- Node::Node() {
- }
- Node::Node(int valor) {
- this->valor = valor;
- this->prox = NULL;
- }
- void Node::setValor(int valor) {
- this->valor = valor;
- }
- void Node::setProx(Node* prox) {
- this->prox = prox;
- }
- int Node::getValor() {
- return this->valor;
- }
- Node* Node::getProx() {
- return this->prox;
- }
- Fila::Fila() {
- this->tamanho = 0;
- }
- void Fila::enfileirar(int valor) {
- if (this->tamanho == 0) {
- this->primeiro = new Node(valor);
- this->ultimo = this->primeiro;
- this->tamanho++;
- }
- else {
- this->ultimo->setProx(new Node(valor));
- this->ultimo = this->ultimo->getProx();
- this->tamanho++;
- }
- }
- int Fila::desenfileirar() {
- int valor;
- Node* aux;
- valor = -1;
- if (this->tamanho == 0) {
- printf("Fila vazia!\n");
- return -1;
- }
- else {
- valor = this->primeiro->getValor();
- aux = this->primeiro;
- this->primeiro = this->primeiro->getProx();
- delete aux;
- this->tamanho--;
- return valor;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement