![](/media/cache/profiles/Felicito_-_New_Avatar.jpg.50x50_q85.jpg)
Proyecto ABInBev para la tarjeta Guaria 1/2.
VoicePlaylist/playlist.cpp
- Committer:
- fmanzano_dtk
- Date:
- 2022-07-07
- Revision:
- 19:5580a9a54ad5
- Parent:
- 1:9e821e640117
File content as of revision 19:5580a9a54ad5:
/** * @file playlist.cpp * @author Felícito Manzano (felicito.manzano@detektor.com.sv) * @brief * @version 0.1 * @date 2020-11-19 * * @copyright Copyright (c) 2020 * */ #include "playlist.hpp" extern int items_queue; // Constructor to initialize queue queue::queue(int size) { arr = new int[size]; capacity = size; front = 0; rear = -1; count = 0; } // Destructor to free memory allocated to the queue queue::~queue() { delete[] arr; } // Utility function to remove front element from the queue void queue::dequeue() { // check for queue underflow if (isEmpty()) { //cout << "UnderFlow\nProgram Terminated\n"; exit(EXIT_FAILURE); } //cout << "Removing " << arr[front] << '\n'; front = (front + 1) % capacity; count--; items_queue--; } // Utility function to add an item to the queue void queue::enqueue(int item) { // check for queue overflow if (isFull()) { // cout << "OverFlow\nProgram Terminated\n"; exit(EXIT_FAILURE); } //cout << "Inserting " << item << '\n'; rear = (rear + 1) % capacity; arr[rear] = item; count++; items_queue++; } // Utility function to return front element in the queue int queue::peek() { if (isEmpty()) { //cout << "UnderFlow\nProgram Terminated\n"; exit(EXIT_FAILURE); } return arr[front]; } // Utility function to return the size of the queue int queue::size() { return count; } // Funcion agregada para limpiar items directamente /* void queue::erase() { memset(arr, '\0', sizeof(arr)); front = 0; rear = -1; count = 0; } */ // Utility function to check if the queue is empty or not bool queue::isEmpty() { return (size() == 0); } // Utility function to check if the queue is full or not bool queue::isFull() { return (size() == capacity); }