Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
120 changes: 120 additions & 0 deletions CPP/Stacks_Queues/circular deque.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*

LEETCODE PROBLEM 641 IMPLEMENTED

*/

#include <vector>
using namespace std;

class MyCircularDeque {
public:
int maxSize; // Maximum size of the deque
vector<int> 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
}
};
Loading