diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..09431ee --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/muhib009/Hacktober_new_2025/DSA-Collection/CPP/Stacks_Queues", + "program": "/home/muhib009/Hacktober_new_2025/DSA-Collection/CPP/Stacks_Queues/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/CPP/Stacks_Queues/circular deque.cpp b/CPP/Stacks_Queues/circular deque.cpp new file mode 100644 index 0000000..c5af0c1 --- /dev/null +++ b/CPP/Stacks_Queues/circular deque.cpp @@ -0,0 +1,120 @@ +/* + +LEETCODE PROBLEM 641 IMPLEMENTED + +*/ + +#include +using namespace std; + +class MyCircularDeque { +public: + int maxSize; // Maximum size of the deque + vector dq; // Vector to store the elements of the deque + int front; // Index of the front element + int rear; // Index of the rear element + + // Constructor to initialize the deque with size k + MyCircularDeque(int k) { + front = -1; // Initialize front index as -1 (indicating empty) + rear = -1; // Initialize rear index as -1 (indicating empty) + maxSize = k; // Set maximum size + dq.resize(maxSize); // Resize the vector to hold maxSize elements + } + + // Function to insert an element at the front + bool insertFront(int value) { + if (isFull()) { + return false; // Return false if the deque is full + } else if (front == -1) { + // If the deque is empty, set front and rear to 0 and insert the value + front = 0; + rear = 0; + dq[front] = value; // Insert value at the front + return true; // Insertion successful + } else { + // Move front index backward and insert the value + front = (front + 1) % maxSize; // Wrap around if necessary + dq[front] = value; // Insert value at the new front + return true; // Insertion successful + } + } + + // Function to insert an element at the rear + bool insertLast(int value) { + if (isFull()) { + return false; // Return false if the deque is full + } else if (rear == -1) { + // If the deque is empty, set front and rear to 0 and insert the value + front = 0; + rear = 0; + dq[rear] = value; // Insert value at the rear + return true; // Insertion successful + } else { + // Move rear index backward and insert the value + rear = (rear - 1 + maxSize) % maxSize; // Wrap around if necessary + dq[rear] = value; // Insert value at the new rear + return true; // Insertion successful + } + } + + // Function to delete the front element + bool deleteFront() { + if (isEmpty()) { + return false; // Return false if the deque is empty + } else if (front == rear) { + // If there's only one element, reset front and rear + front = -1; + rear = -1; + return true; // Deletion successful + } else { + // Move front index backward + front = (front - 1 + maxSize) % maxSize; // Wrap around if necessary + return true; // Deletion successful + } + } + + // Function to delete the last element + bool deleteLast() { + if (isEmpty()) { + return false; // Return false if the deque is empty + } else if (rear == front) { + // If there's only one element, reset front and rear + front = -1; + rear = -1; + return true; // Deletion successful + } else { + // Move rear index forward + rear = (rear + 1) % maxSize; // Wrap around if necessary + return true; // Deletion successful + } + } + + // Function to get the front element + int getFront() { + if (isEmpty()) { + return -1; // Return -1 if the deque is empty + } else { + return dq[front]; // Return the front element + } + } + + // Function to get the last element + int getRear() { + if (isEmpty()) { + return -1; // Return -1 if the deque is empty + } else { + return dq[rear]; // Return the rear element + } + } + + // Function to check if the deque is empty + bool isEmpty() { + return rear == -1; // Return true if rear is -1 (indicating empty) + } + + // Function to check if the deque is full + bool isFull() { + return (front + 1) % maxSize == rear; // Return true if next front position equals rear + } +};