online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> struct Queue { private: constexpr static int initialCapacity = 100; int capacity = 0; int *data = nullptr; int counter = 0; int first = 0; int aftr = 0; public: Queue():data{new int[initialCapacity]},capacity{initialCapacity}{} void push_back(int value) { if ((aftr == capacity) && (counter < capacity)) { for (int i = 0; i < counter; i++) { data[i] = data[first + i]; } first = 0; aftr = counter; } else if(counter == capacity) { capacity = capacity * 2; int *tmp = new int[capacity]; for (int i = 0; i < counter; i++) tmp[i] = data[i]; delete[] data; data = tmp; } data[aftr] = value; aftr++; counter++; } bool empty() { return counter == 0; } int pop_front() { if (counter == 0) { std::cout << "Queue is empty" << std::endl; } int value = data[first]; first++; counter--; return value; } void print() { if (counter == 0) { std::cout << "Empty queue" << std::endl; } else { for (int i = 0; i < counter; i++) { std::cout << data[first + i] << ", "; } std::cout << std::endl; } } int front() { if (counter == 0) std::cout << "Queue is empty" << std::endl; int firstElement = data[first]; return firstElement; } int back() { if (counter == 0) std::cout << ("Queue is empty") << std::endl; int lastElement = data[aftr - 1]; return lastElement; } void rotate(int n) { for (int i = 0; i < n; i++) { const int tmp = front(); pop_front(); push_back(tmp); } } }; int main() { Queue q; q.push_back(3); q.push_back(4); q.push_back(5); q.push_back(6); q.push_back(7); q.print(); q.rotate(1); q.print(); q.rotate(2); q.print(); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue