├── .github └── workflows │ ├── .github │ └── workflows │ │ └── greetings.yml │ └── learn-github-actions.yml ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── C++ ├── Algorithms │ └── Trapping-Rain-Water-42.cpp ├── AvlTree.cpp ├── BinarySearch.cpp ├── CircularQueue.cpp ├── Intersection_of_two_Linked_Lists.cpp ├── QuickSort.cpp ├── RadixSort.cpp ├── RadixSort.exe ├── Search_element_in_2D_matrix.cpp ├── SingleLinkedList.cpp ├── SpiralMatrix.cpp ├── StackOperations.cpp ├── StoreAPolynomial.cpp ├── TicTacToe.cpp ├── TowerofHanoi ├── TowerofHanoi.cpp ├── TwoSorted_LinkedList.cpp ├── bubbleSort.cpp ├── bubbleSort.exe ├── circularQueue ├── heap_insertion.cpp ├── insertion_sort.cpp ├── min_ind_repeating_element.cpp ├── reverseLinkedList ├── reverseLinkedList.cpp ├── stackOperations └── stackOperations.cpp ├── CONTRIBUTING.md ├── CodeRich Website ├── images │ └── hero-bg.png ├── index.html └── style.css ├── JAVA ├── CircularQueue.java ├── Cyclesort.java ├── DoubleLinkedlist.java ├── KthLargest.java ├── MergeSortAlgo.java ├── MergeSortedLinkedLists.java ├── SmallestMissingElement.java └── SudokuSolver,java ├── README.md ├── SECURITY.md └── script.js /.github/workflows/.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | pull-requests: write 10 | steps: 11 | - uses: actions/first-interaction@v1 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | pr-message: "Greetings from Coderich Community! Thanks for making the PR, our team will review it soon. Stay tuned 😊" 15 | -------------------------------------------------------------------------------- /.github/workflows/learn-github-actions.yml: -------------------------------------------------------------------------------- 1 | name: learn-github-actions 2 | run-name: ${{ github.actor }} is learning GitHub Actions 3 | on: [push] 4 | jobs: 5 | check-bats-version: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v4 9 | - uses: actions/setup-node@v3 10 | with: 11 | node-version: '14' 12 | - run: npm install -g bats 13 | - run: bats -v 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | C++/circularQueue.cpp 3 | C++/circularQueue.cpp 4 | C++/stackOperations.cpp 5 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "C:/mingw64/bin/gcc.exe", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "" 14 | ] 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "externalConsole": true, 11 | "cwd": ".", 12 | "program": "build/Debug/outDebug", 13 | "MIMode": "gdb", 14 | "miDebuggerPath": "gdb", 15 | "setupCommands": [ 16 | { 17 | "description": "Enable pretty-printing for gdb", 18 | "text": "-enable-pretty-printing", 19 | "ignoreFailures": true 20 | } 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.cCompilerPath": "gcc", 3 | "C_Cpp_Runner.cppCompilerPath": "g++", 4 | "C_Cpp_Runner.debuggerPath": "gdb", 5 | "C_Cpp_Runner.cStandard": "", 6 | "C_Cpp_Runner.cppStandard": "", 7 | "C_Cpp_Runner.msvcBatchPath": "", 8 | "C_Cpp_Runner.useMsvc": false, 9 | "C_Cpp_Runner.warnings": [ 10 | "-Wall", 11 | "-Wextra", 12 | "-Wpedantic", 13 | "-Wshadow", 14 | "-Wformat=2", 15 | "-Wcast-align", 16 | "-Wconversion", 17 | "-Wsign-conversion", 18 | "-Wnull-dereference" 19 | ], 20 | "C_Cpp_Runner.msvcWarnings": [ 21 | "/W4", 22 | "/permissive-", 23 | "/w14242", 24 | "/w14287", 25 | "/w14296", 26 | "/w14311", 27 | "/w14826", 28 | "/w44062", 29 | "/w44242", 30 | "/w14905", 31 | "/w14906", 32 | "/w14263", 33 | "/w44265", 34 | "/w14928" 35 | ], 36 | "C_Cpp_Runner.enableWarnings": true, 37 | "C_Cpp_Runner.warningsAsError": false, 38 | "C_Cpp_Runner.compilerArgs": [], 39 | "C_Cpp_Runner.linkerArgs": [], 40 | "C_Cpp_Runner.includePaths": [], 41 | "C_Cpp_Runner.includeSearch": [ 42 | "*", 43 | "**/*" 44 | ], 45 | "C_Cpp_Runner.excludeSearch": [ 46 | "**/build", 47 | "**/build/**", 48 | "**/.*", 49 | "**/.*/**", 50 | "**/.vscode", 51 | "**/.vscode/**" 52 | ], 53 | "C_Cpp_Runner.useAddressSanitizer": false, 54 | "C_Cpp_Runner.useUndefinedSanitizer": false, 55 | "C_Cpp_Runner.useLeakSanitizer": false, 56 | "C_Cpp_Runner.showCompilationTime": false, 57 | "C_Cpp_Runner.useLinkTimeOptimization": false, 58 | "C_Cpp_Runner.msvcSecureNoWarnings": false, 59 | "files.associations": { 60 | "iostream": "cpp" 61 | } 62 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++ build active file", 6 | "command": "/usr/bin/g++", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}/${fileBasenameNoExtension}" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /C++/Algorithms/Trapping-Rain-Water-42.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int trap(vector& height) { 4 | int n = height.size(); 5 | // prev greatest element array 6 | int prev[n]; 7 | prev[0] = -1; 8 | int max = height[0]; 9 | for(int i = 0;i prev as next 15 | 16 | //int next[n]; 17 | 18 | prev[n-1] = -1; 19 | max = height[n-1]; 20 | for(int i = n-1;i>0;i--){ 21 | if(max prev as minimum 26 | // // int mini[n]; 27 | // for(int i=0;i 2 | using namespace std; 3 | 4 | class Node { 5 | public: 6 | int key; 7 | Node* left; 8 | Node* right; 9 | int height; 10 | Node(int k) : key(k), left(nullptr), right(nullptr), height(1) {} 11 | }; 12 | 13 | class AVLTree { 14 | private: 15 | Node* root; 16 | 17 | int getHeight(Node* node) { 18 | if (node == nullptr) 19 | return 0; 20 | return node->height; 21 | } 22 | 23 | int getBalanceFactor(Node* node) { 24 | if (node == nullptr) 25 | return 0; 26 | return getHeight(node->left) - getHeight(node->right); 27 | } 28 | 29 | void updateHeight(Node* node) { 30 | if (node != nullptr) 31 | node->height = 1 + max(getHeight(node->left), getHeight(node->right)); 32 | } 33 | 34 | Node* rotateRight(Node* y) { 35 | Node* x = y->left; 36 | Node* T2 = x->right; 37 | x->right = y; 38 | y->left = T2; 39 | updateHeight(y); 40 | updateHeight(x); 41 | return x; 42 | } 43 | 44 | Node* rotateLeft(Node* x) { 45 | Node* y = x->right; 46 | Node* T2 = y->left; 47 | y->left = x; 48 | x->right = T2; 49 | updateHeight(x); 50 | updateHeight(y); 51 | return y; 52 | } 53 | 54 | Node* insert(Node* node, int key) { 55 | if (node == nullptr) 56 | return new Node(key); 57 | if (key < node->key) 58 | node->left = insert(node->left, key); 59 | else if (key > node->key) 60 | node->right = insert(node->right, key); 61 | else 62 | return node; 63 | 64 | updateHeight(node); 65 | 66 | int balance = getBalanceFactor(node); 67 | 68 | // Left Heavy 69 | if (balance > 1) { 70 | if (key < node->left->key) // Left-Left case 71 | return rotateRight(node); 72 | if (key > node->left->key) { // Left-Right case 73 | node->left = rotateLeft(node->left); 74 | return rotateRight(node); 75 | } 76 | } 77 | // Right Heavy 78 | if (balance < -1) { 79 | if (key > node->right->key) // Right-Right case 80 | return rotateLeft(node); 81 | if (key < node->right->key) { // Right-Left case 82 | node->right = rotateRight(node->right); 83 | return rotateLeft(node); 84 | } 85 | } 86 | 87 | return node; 88 | } 89 | 90 | public: 91 | AVLTree() : root(nullptr) {} 92 | 93 | void insert(int key) { 94 | root = insert(root, key); 95 | } 96 | 97 | void display(Node* node, int indent = 0) { 98 | if (node != nullptr) { 99 | display(node->right, indent + 4); 100 | cout << string(indent, ' ') << node->key << endl; 101 | display(node->left, indent + 4); 102 | } 103 | } 104 | 105 | void displayTree() { 106 | display(root); 107 | } 108 | }; 109 | 110 | int main() { 111 | AVLTree tree; 112 | tree.insert(10); 113 | tree.insert(20); 114 | tree.insert(30); 115 | tree.insert(40); 116 | tree.insert(50); 117 | 118 | tree.displayTree(); 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /C++/BinarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int solve(int dividend, int divisor) { 5 | int s = 0; 6 | int e = abs(dividend); 7 | int ans = 0; 8 | int mid = s + (e-s)/2; 9 | while(s <= e) { 10 | //perfect solution 11 | if( abs(mid*divisor) == abs(dividend)) { 12 | ans = mid; 13 | break; 14 | } 15 | //not perfect sol 16 | if(abs(mid*divisor) > abs(dividend)) { 17 | //left 18 | e = mid - 1; 19 | } 20 | else { 21 | //ans store 22 | ans = mid; 23 | //right search 24 | s = mid + 1; 25 | } 26 | mid = s + (e-s)/2; 27 | } 28 | 29 | if((divisor<0 && dividend<0) || (divisor>0 && dividend>0)) 30 | return ans; 31 | else { 32 | return -ans; 33 | } 34 | 35 | } 36 | 37 | int main() { 38 | int dividend = -21; 39 | int divisor = -7; 40 | 41 | int ans = solve(dividend, divisor); 42 | cout << "Ans is-> " << ans << endl; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /C++/CircularQueue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MAX_SIZE = 5; // Maximum size of the queue 5 | 6 | class CircularQueue { 7 | private: 8 | int front, rear; 9 | int arr[MAX_SIZE]; 10 | 11 | public: 12 | CircularQueue() { 13 | front = rear = -1; 14 | } 15 | 16 | // check if the queue is empty 17 | bool isEmpty() { 18 | return (front == -1 && rear == -1); 19 | } 20 | 21 | // check if the queue is full 22 | bool isFull() { 23 | return (front == (rear + 1) % MAX_SIZE); 24 | } 25 | 26 | // enqueue an element 27 | void enqueue(int value) { 28 | if (isFull()) { 29 | cout << "Queue is full. Cannot enqueue." << endl; 30 | return; 31 | } 32 | if (isEmpty()) { 33 | front = rear = 0; // 34 | } else { 35 | rear = (rear + 1) % MAX_SIZE; // Circular increment of rear 36 | } 37 | arr[rear] = value; 38 | cout << value << " enqueued to the queue." << endl; 39 | } 40 | 41 | // dequeue an element 42 | void dequeue() { 43 | if (isEmpty()) { 44 | cout << "Queue is empty. Cannot dequeue." << endl; 45 | return; 46 | } 47 | cout << arr[front] << " dequeued from the queue." << endl; 48 | if (front == rear) { 49 | front = rear = -1; 50 | } else { 51 | front = (front + 1) % MAX_SIZE; // Circular increment of front 52 | } 53 | } 54 | 55 | // display the elements of the queue 56 | void display() { 57 | if (isEmpty()) { 58 | cout << "Queue is empty." << endl; 59 | return; 60 | } 61 | cout << "Elements in the queue: "; 62 | int i = front; 63 | while (true) { 64 | cout << arr[i] << " "; 65 | if (i == rear) 66 | break; 67 | i = (i + 1) % MAX_SIZE; // Circular increment of index 68 | } 69 | cout << endl; 70 | } 71 | }; 72 | 73 | int main() { 74 | CircularQueue queue; 75 | queue.enqueue(1); 76 | queue.enqueue(2); 77 | queue.enqueue(3); 78 | queue.display(); 79 | queue.dequeue(); 80 | queue.display(); 81 | queue.enqueue(4); 82 | queue.enqueue(5); 83 | queue.display(); 84 | queue.enqueue(6); // This will show an error as the queue is full. 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /C++/Intersection_of_two_Linked_Lists.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://leetcode.com/problems/intersection-of-two-linked-lists/ 2 | 3 | class Solution { 4 | public: 5 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 6 | ListNode *temp; 7 | while(headA != NULL){ 8 | temp = headB; 9 | while(temp != NULL){ 10 | if(headA == temp){ 11 | return headA; 12 | } 13 | temp = temp -> next; 14 | } 15 | headA = headA -> next; 16 | } 17 | return NULL; 18 | } 19 | }; -------------------------------------------------------------------------------- /C++/QuickSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void quickSort(int list[], int start, int end); 4 | int partition(int list[], int start, int end); 5 | 6 | int main() 7 | { 8 | int arr [9] = {3,5,4,1,6,7,9,8,2}; 9 | int length = 9; 10 | 11 | quickSort(arr, 0, length); 12 | for(int i = 0; i < length; i++) 13 | { 14 | std::cout << arr[i]; 15 | } 16 | return 0; 17 | } 18 | 19 | void quickSort(int list[], int start, int end) 20 | { 21 | // base case 22 | if (end <= start) 23 | { 24 | return; 25 | } 26 | int pivot = partition(list, start, end); 27 | quickSort(list, start, pivot - 1); 28 | quickSort(list, pivot + 1, end); 29 | } 30 | 31 | int partition(int list[], int start, int end) 32 | { 33 | int pivot = list[end]; 34 | int i = start - 1; 35 | int temp; 36 | 37 | for(int j = start; j <= end - 1; j++) 38 | { 39 | if(list[j] < pivot) 40 | { 41 | i++; 42 | temp = list[i]; 43 | list[i] = list[j]; 44 | list[j] = temp; 45 | } 46 | } 47 | i++; 48 | temp = list[i]; 49 | list[i] = pivot; 50 | list[end] = temp; 51 | return i; 52 | } -------------------------------------------------------------------------------- /C++/RadixSort.cpp: -------------------------------------------------------------------------------- 1 | // Radix Sort in C++ Programming 2 | 3 | #include 4 | using namespace std; 5 | 6 | // Function to get the largest element from an array 7 | int getMax(int array[], int n) { 8 | int max = array[0]; 9 | for (int i = 1; i < n; i++) 10 | if (array[i] > max) 11 | max = array[i]; 12 | return max; 13 | } 14 | 15 | // Using counting sort to sort the elements in the basis of significant places 16 | void countingSort(int array[], int size, int place) { 17 | const int max = 10; 18 | int output[size]; 19 | int count[max]; 20 | 21 | for (int i = 0; i < max; ++i) 22 | count[i] = 0; 23 | 24 | // Calculate count of elements 25 | for (int i = 0; i < size; i++) 26 | count[(array[i] / place) % 10]++; 27 | 28 | // Calculate cumulative count 29 | for (int i = 1; i < max; i++) 30 | count[i] += count[i - 1]; 31 | 32 | // Place the elements in sorted order 33 | for (int i = size - 1; i >= 0; i--) { 34 | output[count[(array[i] / place) % 10] - 1] = array[i]; 35 | count[(array[i] / place) % 10]--; 36 | } 37 | 38 | for (int i = 0; i < size; i++) 39 | array[i] = output[i]; 40 | } 41 | 42 | // Main function to implement radix sort 43 | void radixsort(int array[], int size) { 44 | // Get maximum element 45 | int max = getMax(array, size); 46 | 47 | // Apply counting sort to sort elements based on place value. 48 | for (int place = 1; max / place > 0; place *= 10) 49 | countingSort(array, size, place); 50 | } 51 | 52 | // Print an array 53 | void printArray(int array[], int size) { 54 | int i; 55 | for (i = 0; i < size; i++) 56 | cout << array[i] << " "; 57 | cout << endl; 58 | } 59 | 60 | // Driver code 61 | int main() { 62 | int array[] = {121, 432, 564, 23, 1, 45, 788}; 63 | int n = sizeof(array) / sizeof(array[0]); 64 | radixsort(array, n); 65 | printArray(array, n); 66 | } -------------------------------------------------------------------------------- /C++/RadixSort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coderich-Community/Hacktoberfest-2023/6cd6ad2520f692bfa840fba80038c56aef83451b/C++/RadixSort.exe -------------------------------------------------------------------------------- /C++/Search_element_in_2D_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool searchMatrix(vector> &mat, int target) 6 | { 7 | int n = mat.size(); 8 | int m = mat[0].size(); 9 | 10 | int low = 0; 11 | int high = (n * m) - 1; 12 | 13 | while (low <= high) 14 | { 15 | int mid = low + (high - low) / 2; 16 | int ele = mat[mid / m][mid % m]; 17 | 18 | if (ele == target) 19 | return true; 20 | 21 | if (ele < target) 22 | low = mid + 1; 23 | 24 | else 25 | high = mid - 1; 26 | } 27 | 28 | return false; 29 | } 30 | 31 | int main() 32 | { 33 | 34 | vector> arr = { 35 | {1, 2, 3}, 36 | {4, 5, 6}, 37 | {7, 8, 9}}; 38 | 39 | int k = 5; 40 | 41 | cout << searchMatrix(arr, k) << endl; 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /C++/SingleLinkedList.cpp: -------------------------------------------------------------------------------- 1 | // Linked list operations in C++ 2 | 3 | #include 4 | 5 | #include 6 | using namespace std; 7 | 8 | // Create a node 9 | struct Node { 10 | int data; 11 | struct Node* next; 12 | }; 13 | 14 | void insertAtBeginning(struct Node** head_ref, int new_data) { 15 | // Allocate memory to a node 16 | struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); 17 | 18 | // insert the data 19 | new_node->data = new_data; 20 | new_node->next = (*head_ref); 21 | 22 | // Move head to new node 23 | (*head_ref) = new_node; 24 | } 25 | 26 | // Insert a node after a node 27 | void insertAfter(struct Node* prev_node, int new_data) { 28 | if (prev_node == NULL) { 29 | cout << "the given previous node cannot be NULL"; 30 | return; 31 | } 32 | 33 | struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); 34 | new_node->data = new_data; 35 | new_node->next = prev_node->next; 36 | prev_node->next = new_node; 37 | } 38 | 39 | // Insert at the end 40 | void insertAtEnd(struct Node** head_ref, int new_data) { 41 | struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); 42 | struct Node* last = *head_ref; /* used in step 5*/ 43 | 44 | new_node->data = new_data; 45 | new_node->next = NULL; 46 | 47 | if (*head_ref == NULL) { 48 | *head_ref = new_node; 49 | return; 50 | } 51 | 52 | while (last->next != NULL) last = last->next; 53 | 54 | last->next = new_node; 55 | return; 56 | } 57 | 58 | // Delete a node 59 | void deleteNode(struct Node** head_ref, int key) { 60 | struct Node *temp = *head_ref, *prev; 61 | 62 | if (temp != NULL && temp->data == key) { 63 | *head_ref = temp->next; 64 | free(temp); 65 | return; 66 | } 67 | // Find the key to be deleted 68 | while (temp != NULL && temp->data != key) { 69 | prev = temp; 70 | temp = temp->next; 71 | } 72 | 73 | // If the key is not present 74 | if (temp == NULL) return; 75 | 76 | // Remove the node 77 | prev->next = temp->next; 78 | 79 | free(temp); 80 | } 81 | 82 | // Search a node 83 | bool searchNode(struct Node** head_ref, int key) { 84 | struct Node* current = *head_ref; 85 | 86 | while (current != NULL) { 87 | if (current->data == key) return true; 88 | current = current->next; 89 | } 90 | return false; 91 | } 92 | 93 | // Sort the linked list 94 | void sortLinkedList(struct Node** head_ref) { 95 | struct Node *current = *head_ref, *index = NULL; 96 | int temp; 97 | 98 | if (head_ref == NULL) { 99 | return; 100 | } else { 101 | while (current != NULL) { 102 | // index points to the node next to current 103 | index = current->next; 104 | 105 | while (index != NULL) { 106 | if (current->data > index->data) { 107 | temp = current->data; 108 | current->data = index->data; 109 | index->data = temp; 110 | } 111 | index = index->next; 112 | } 113 | current = current->next; 114 | } 115 | } 116 | } 117 | 118 | // Print the linked list 119 | void printList(struct Node* node) { 120 | while (node != NULL) { 121 | cout << node->data << " "; 122 | node = node->next; 123 | } 124 | } 125 | 126 | // Driver program 127 | int main() { 128 | struct Node* head = NULL; 129 | 130 | insertAtEnd(&head, 1); 131 | insertAtBeginning(&head, 2); 132 | insertAtBeginning(&head, 3); 133 | insertAtEnd(&head, 4); 134 | insertAfter(head->next, 5); 135 | 136 | cout << "Linked list: "; 137 | printList(head); 138 | 139 | cout << "\nAfter deleting an element: "; 140 | deleteNode(&head, 3); 141 | printList(head); 142 | 143 | int item_to_find = 3; 144 | if (searchNode(&head, item_to_find)) { 145 | cout << endl << item_to_find << " is found"; 146 | } else { 147 | cout << endl << item_to_find << " is not found"; 148 | } 149 | 150 | sortLinkedList(&head); 151 | cout << "\nSorted List: "; 152 | printList(head); 153 | } -------------------------------------------------------------------------------- /C++/SpiralMatrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int m,n; 5 | cout<<"Enter r :"; 6 | cin>>m; 7 | cout<<"Enter c :"; 8 | cin>>n; 9 | int arr[m][n]; 10 | 11 | for(int i = 0;i>arr[i][j]; 14 | } 15 | } 16 | cout<=minc && count=minr && count 2 | #include 3 | 4 | using namespace std; // Add this line to use the std namespace 5 | 6 | class Stack { 7 | private: 8 | vector stack; 9 | 10 | public: 11 | void push(int value) { 12 | stack.push_back(value); 13 | } 14 | 15 | void pop() { 16 | if (!isEmpty()) { 17 | stack.pop_back(); 18 | } else { 19 | cout << "Stack is empty. Cannot pop." << endl; 20 | } 21 | } 22 | 23 | int top() { 24 | if (!isEmpty()) { 25 | return stack.back(); 26 | } else { 27 | cout << "Stack is empty. No top element." << endl; 28 | return -1; // Return a default value indicating an empty stack. 29 | } 30 | } 31 | 32 | bool isEmpty() { 33 | return stack.empty(); 34 | } 35 | }; 36 | 37 | int main() { 38 | Stack myStack; 39 | 40 | myStack.push(10); 41 | myStack.push(20); 42 | myStack.push(30); 43 | 44 | cout << "Top element: " << myStack.top() << endl; 45 | 46 | myStack.pop(); 47 | myStack.pop(); 48 | 49 | cout << "Top element after pops: " << myStack.top() << endl; 50 | 51 | myStack.pop(); 52 | myStack.pop(); // Trying pop from an empty stack 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /C++/StoreAPolynomial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Term { 5 | int coefficient; 6 | int exponent; 7 | Term* next; 8 | }; 9 | 10 | void insertTerm(Term*& head, int coefficient, int exponent) { 11 | Term* newTerm = new Term; 12 | newTerm->coefficient = coefficient; 13 | newTerm->exponent = exponent; 14 | newTerm->next = nullptr; 15 | 16 | if (!head) { 17 | head = newTerm; 18 | } else { 19 | Term* current = head; 20 | Term* prev = nullptr; 21 | 22 | while (current && current->exponent > exponent) { 23 | prev = current; 24 | current = current->next; 25 | } 26 | 27 | if (current && current->exponent == exponent) { 28 | current->coefficient += coefficient; 29 | delete newTerm; 30 | } else { 31 | newTerm->next = current; 32 | if (prev) { 33 | prev->next = newTerm; 34 | } else { 35 | head = newTerm; 36 | } 37 | } 38 | } 39 | } 40 | 41 | void displayPolynomial(Term* head) { 42 | Term* current = head; 43 | while (current) { 44 | cout << current->coefficient << "x^" << current->exponent; 45 | if (current->next) { 46 | cout << " + "; 47 | } 48 | current = current->next; 49 | } 50 | cout << endl; 51 | } 52 | 53 | int main() { 54 | Term* polynomial = nullptr; 55 | 56 | insertTerm(polynomial, 5, 2); 57 | insertTerm(polynomial, 3, 1); 58 | cout << "Polynomial: "; 59 | displayPolynomial(polynomial); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /C++/TicTacToe.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Function to display the Tic-Tac-Toe board 5 | void displayBoard(char board[3][3]) { 6 | for (int i = 0; i < 3; i++) { 7 | for (int j = 0; j < 3; j++) { 8 | cout << board[i][j]; 9 | if (j < 2) cout << " | "; 10 | } 11 | cout << endl; 12 | if (i < 2) cout << "---------" << endl; 13 | } 14 | } 15 | 16 | // Function to check if a player has won 17 | bool checkWin(char board[3][3], char player) { 18 | // Check rows and columns 19 | for (int i = 0; i < 3; i++) { 20 | if ((board[i][0] == player && board[i][1] == player && board[i][2] == player) || 21 | (board[0][i] == player && board[1][i] == player && board[2][i] == player)) { 22 | return true; 23 | } 24 | } 25 | 26 | // Check diagonals 27 | if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) || 28 | (board[0][2] == player && board[1][1] == player && board[2][0] == player)) { 29 | return true; 30 | } 31 | 32 | return false; 33 | } 34 | 35 | // Function to check if the board is full (a tie) 36 | bool isBoardFull(char board[3][3]) { 37 | for (int i = 0; i < 3; i++) { 38 | for (int j = 0; j < 3; j++) { 39 | if (board[i][j] == ' ') { 40 | return false; 41 | } 42 | } 43 | } 44 | return true; 45 | } 46 | 47 | int main() { 48 | char board[3][3] = { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } }; 49 | char currentPlayer = 'X'; 50 | int row, col; 51 | 52 | cout << "Welcome to Tic-Tac-Toe!" << endl; 53 | 54 | while (true) { 55 | // Display the current state of the board 56 | displayBoard(board); 57 | 58 | // Get the player's move 59 | cout << "Player " << currentPlayer << ", enter row (0, 1, or 2) and column (0, 1, or 2): "; 60 | cin >> row >> col; 61 | 62 | // Check if the input is valid 63 | if (row < 0 || row > 2 || col < 0 || col > 2 || board[row][col] != ' ') { 64 | cout << "Invalid move. Try again." << endl; 65 | continue; 66 | } 67 | 68 | // Make the move 69 | board[row][col] = currentPlayer; 70 | 71 | // Check for a win or a tie 72 | if (checkWin(board, currentPlayer)) { 73 | displayBoard(board); 74 | cout << "Player " << currentPlayer << " wins! Congratulations!" << endl; 75 | break; 76 | } else if (isBoardFull(board)) { 77 | displayBoard(board); 78 | cout << "It's a tie! The game is over." << endl; 79 | break; 80 | } 81 | 82 | // Switch to the other player 83 | currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; 84 | } 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /C++/TowerofHanoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coderich-Community/Hacktoberfest-2023/6cd6ad2520f692bfa840fba80038c56aef83451b/C++/TowerofHanoi -------------------------------------------------------------------------------- /C++/TowerofHanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void towerOfHanoi(int n, char source, char auxiliary, char destination) { 5 | if (n == 1) { 6 | cout << "Move disk 1 from " << source << " to " << destination << endl; 7 | return; 8 | } 9 | 10 | towerOfHanoi(n - 1, source, destination, auxiliary); 11 | cout << "Move disk " << n << " from " << source << " to " << destination << endl; 12 | towerOfHanoi(n - 1, auxiliary, source, destination); 13 | } 14 | 15 | int main() { 16 | int n; 17 | cout << "Enter the number of disks: "; 18 | cin >> n; 19 | 20 | towerOfHanoi(n, 'A', 'B', 'C'); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C++/TwoSorted_LinkedList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Define a struct for a singly linked list node 4 | struct ListNode { 5 | int val; 6 | ListNode* next; 7 | ListNode(int x) : val(x), next(nullptr) {} 8 | }; 9 | 10 | // Function to merge two sorted linked lists 11 | ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { 12 | // Create a dummy node as the head of the merged list 13 | ListNode dummy(0); 14 | ListNode* current = &dummy; 15 | 16 | // Iterate through the input lists 17 | while (l1 != nullptr && l2 != nullptr) { 18 | if (l1->val < l2->val) { 19 | current->next = l1; 20 | l1 = l1->next; 21 | } else { 22 | current->next = l2; 23 | l2 = l2->next; 24 | } 25 | current = current->next; 26 | } 27 | 28 | // If one of the lists is exhausted, append the remaining list 29 | if (l1 != nullptr) { 30 | current->next = l1; 31 | } else { 32 | current->next = l2; 33 | } 34 | 35 | return dummy.next; // The merged list starts from the next of the dummy node 36 | } 37 | 38 | // Function to print a linked list 39 | void printList(ListNode* head) { 40 | while (head != nullptr) { 41 | std::cout << head->val << " -> "; 42 | head = head->next; 43 | } 44 | std::cout << "nullptr" << std::endl; 45 | } 46 | 47 | int main() { 48 | // Example usage 49 | ListNode* list1 = new ListNode(1); 50 | list1->next = new ListNode(3); 51 | list1->next->next = new ListNode(5); 52 | 53 | ListNode* list2 = new ListNode(2); 54 | list2->next = new ListNode(4); 55 | list2->next->next = new ListNode(6); 56 | 57 | std::cout << "List 1: "; 58 | printList(list1); 59 | 60 | std::cout << "List 2: "; 61 | printList(list2); 62 | 63 | ListNode* mergedList = mergeTwoLists(list1, list2); 64 | 65 | std::cout << "Merged List: "; 66 | printList(mergedList); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /C++/bubbleSort.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | void printArray(int*A, int n){ 6 | for (int i = 0; i < n; i++) 7 | { 8 | cout<A[j+1]){ 22 | int temp = A[j]; 23 | A[j] = A[j+1]; 24 | A[j+1] = temp; 25 | isSorted = 0; 26 | } 27 | } 28 | if(isSorted){ 29 | return ; 30 | } 31 | 32 | } 33 | 34 | } 35 | int main(){ 36 | int A[] = {12,3,45,54,23,21}; 37 | // int A[] = {1,5,6,9,12,34}; // it takes only one pass so fucntion is adaptive 38 | int n = 6; // to give size of A[] 39 | bubbleSort(A,n); //function to sort array 40 | printArray(A,n); // to print array 41 | cout< 2 | using namespace std; 3 | 4 | class heap 5 | { 6 | public: 7 | int arr[100]; 8 | int size ; 9 | heap(){ 10 | arr[0] = -1; 11 | size = 0; 12 | } 13 | 14 | void insertion(int val) 15 | { 16 | size = size + 1; 17 | int index = size; 18 | arr[index] = val; 19 | int parent; 20 | while (index > 1) 21 | { 22 | parent = index / 2; 23 | if (arr[parent] < arr[index]) 24 | { 25 | swap(arr[parent], arr[index]); 26 | index = parent; 27 | } 28 | else{ 29 | return; 30 | } 31 | } 32 | } 33 | 34 | void print(){ 35 | for (int i = 0; i <= size; i++) 36 | { 37 | cout< 2 | using namespace std; 3 | 4 | void printArray(int*A, int n){ 5 | for (int i = 0; i < n; i++) 6 | { 7 | cout<= 0 && A[j]>key) 17 | { 18 | A[j+1] = A[j]; 19 | j--; 20 | } 21 | A[j+1] = key; 22 | } 23 | } 24 | 25 | int main(){ 26 | int A[] = {12,43,9,65,23,11}; 27 | int n = 6; 28 | printArray(A,n); 29 | cout< 2 | using namespace std; 3 | 4 | int find_min_ind_repeating_ele(int arr[],int size){ 5 | for(int i=0;i>size; 19 | cout<<"Enter elements: "<>Mainarr[i]; 23 | } 24 | int result = find_min_ind_repeating_ele(Mainarr,size); 25 | if(result!=-1){ 26 | cout<<"Minimum index of repeating element is: "< 2 | 3 | using namespace std; 4 | 5 | 6 | class Node { 7 | public: 8 | int data; 9 | Node* next; 10 | 11 | Node(int val) { 12 | data = val; 13 | next = nullptr; 14 | } 15 | }; 16 | 17 | 18 | class LinkedList { 19 | public: 20 | Node* head; 21 | 22 | 23 | LinkedList() { 24 | head = nullptr; 25 | } 26 | 27 | // insert a new element at the beginning of the linked list. 28 | void insert(int val) { 29 | Node* newNode = new Node(val); 30 | newNode->next = head; 31 | head = newNode; 32 | } 33 | 34 | // display the linked list elements. 35 | void display() { 36 | Node* current = head; 37 | while (current != nullptr) { 38 | cout << current->data << " -> "; 39 | current = current->next; 40 | } 41 | cout << "nullptr" << endl; 42 | } 43 | 44 | // reverse the linked list. 45 | void reverse() { 46 | Node* prev = nullptr; 47 | Node* current = head; 48 | Node* nextNode = nullptr; 49 | 50 | // Traverse the list 51 | while (current != nullptr) { 52 | nextNode = current->next; 53 | current->next = prev; 54 | prev = current; 55 | current = nextNode; 56 | } 57 | 58 | head = prev; // Set the new head. 59 | } 60 | }; 61 | 62 | int main() { 63 | LinkedList list; 64 | list.insert(1); 65 | list.insert(2); 66 | list.insert(3); 67 | list.insert(4); 68 | 69 | cout << "Original Linked List: "; 70 | list.display(); 71 | 72 | list.reverse(); 73 | 74 | cout << "Reversed Linked List: "; 75 | list.display(); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /C++/stackOperations: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coderich-Community/Hacktoberfest-2023/6cd6ad2520f692bfa840fba80038c56aef83451b/C++/stackOperations -------------------------------------------------------------------------------- /C++/stackOperations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; // Add this line to use the std namespace 5 | 6 | class Stack { 7 | private: 8 | vector stack; 9 | 10 | public: 11 | void push(int value) { 12 | stack.push_back(value); 13 | } 14 | 15 | void pop() { 16 | if (!isEmpty()) { 17 | stack.pop_back(); 18 | } else { 19 | cout << "Stack is empty. Cannot pop." << endl; 20 | } 21 | } 22 | 23 | int top() { 24 | if (!isEmpty()) { 25 | return stack.back(); 26 | } else { 27 | cout << "Stack is empty. No top element." << endl; 28 | return -1; // Return a default value indicating an empty stack. 29 | } 30 | } 31 | 32 | bool isEmpty() { 33 | return stack.empty(); 34 | } 35 | }; 36 | 37 | int main() { 38 | Stack myStack; 39 | 40 | myStack.push(10); 41 | myStack.push(20); 42 | myStack.push(30); 43 | 44 | cout << "Top element: " << myStack.top() << endl; 45 | 46 | myStack.pop(); 47 | myStack.pop(); 48 | 49 | cout << "Top element after pops: " << myStack.top() << endl; 50 | 51 | myStack.pop(); 52 | myStack.pop(); // Trying pop from an empty stack 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Follow the below format to add your name: 2 | 3 | 4 | 5 | ```markdown 6 | #### Name: 7 | 8 | - GitHub: https://github.com// 9 | ``` 10 | 11 | ```markdown 12 | #### Name: Md Samer ANsari 13 | 14 | - GitHub: https://github.com/mrsamirr 15 | ``` 16 | 17 | ```markdown 18 | #### Name: Mansi Prajapati 19 | 20 | - GitHub: https://github.com/Mansiprajapatii 21 | ``` 22 | 23 | ```markdown 24 | #### Name: Arshad M. Patel 25 | 26 | - GitHub: https://github.com/arshadpatel 27 | ``` 28 | -------------------------------------------------------------------------------- /CodeRich Website/images/hero-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coderich-Community/Hacktoberfest-2023/6cd6ad2520f692bfa840fba80038c56aef83451b/CodeRich Website/images/hero-bg.png -------------------------------------------------------------------------------- /CodeRich Website/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | CodeRich Community 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 35 |
36 |
37 |
38 |

E-Learning Platform

39 |

40 | "Embark on an exciting programming journey to bring your ideas to life. Discover limitless possibilities as you master the art of coding and play a pivotal role in shaping our digital future." 41 |

42 |
43 | Join Now 44 | Learn More 45 |
46 |
47 |
48 | hero image 49 |
50 |
51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /CodeRich Website/style.css: -------------------------------------------------------------------------------- 1 | /* Importing Google font - Open Sans */ 2 | @import url("https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap"); 3 | 4 | * { 5 | margin: 0; 6 | padding: 0; 7 | box-sizing: border-box; 8 | font-family: "Open Sans", sans-serif; 9 | } 10 | 11 | body { 12 | height: 100vh; 13 | width: 100%; 14 | background: linear-gradient(to bottom, #246b7b 23%, #432a82 95%); 15 | 16 | } 17 | 18 | .header { 19 | position: fixed; 20 | top: 0; 21 | left: 0; 22 | width: 100%; 23 | } 24 | 25 | .navbar { 26 | display: flex; 27 | align-items: center; 28 | justify-content: space-between; 29 | max-width: 1200px; 30 | margin: 0 auto; 31 | padding: 20px 15px; 32 | } 33 | 34 | .navbar .logo a { 35 | font-size: 1.8rem; 36 | text-decoration: none; 37 | color: #fff; 38 | } 39 | 40 | .navbar .links { 41 | display: flex; 42 | align-items: center; 43 | list-style: none; 44 | gap: 35px; 45 | } 46 | 47 | .navbar .links a { 48 | font-weight: 500; 49 | text-decoration: none; 50 | color: #fff; 51 | padding: 10px 0; 52 | transition: 0.2s ease; 53 | } 54 | 55 | .navbar .links a:hover { 56 | color: #47b2e4; 57 | } 58 | 59 | .navbar .buttons a { 60 | text-decoration: none; 61 | color: #fff; 62 | font-size: 1rem; 63 | padding: 15px 0; 64 | transition: 0.2s ease; 65 | } 66 | 67 | .navbar .buttons a:not(:last-child) { 68 | margin-right: 30px; 69 | } 70 | 71 | .navbar .buttons .signin:hover { 72 | color: #47b2e4; 73 | } 74 | 75 | .navbar .buttons .signup { 76 | border: 1px solid #fff; 77 | padding: 10px 20px; 78 | border-radius: 0.375rem; 79 | text-align: center; 80 | transition: 0.2s ease; 81 | } 82 | 83 | .navbar .buttons .signup:hover { 84 | background-color: #47b2e4; 85 | color: #fff; 86 | } 87 | 88 | .hero-section { 89 | display: flex; 90 | justify-content: space-evenly; 91 | align-items: center; 92 | height: 95vh; 93 | padding: 0 15px; 94 | max-width: 1200px; 95 | margin: 0 auto; 96 | } 97 | 98 | .hero-section .hero { 99 | max-width: 50%; 100 | color: #fff; 101 | } 102 | 103 | .hero h2 { 104 | font-size: 2.5rem; 105 | margin-bottom: 20px; 106 | } 107 | 108 | .hero p { 109 | font-size: 1.2rem; 110 | margin-bottom: 20px; 111 | color: #c9c7c7; 112 | } 113 | 114 | .hero-section .img img { 115 | width: 517px; 116 | } 117 | 118 | .hero-section .buttons { 119 | margin-top: 40px; 120 | } 121 | 122 | .hero-section .buttons a { 123 | text-decoration: none; 124 | color: #fff; 125 | padding: 12px 24px; 126 | border-radius: 0.375rem; 127 | font-weight: 600; 128 | transition: 0.2s ease; 129 | display: inline-block; 130 | } 131 | 132 | .hero-section .buttons a:not(:last-child) { 133 | margin-right: 15px; 134 | } 135 | 136 | .buttons .join { 137 | background-color: #47b2e4; 138 | } 139 | 140 | .hero-section .buttons .learn { 141 | border: 1px solid #fff; 142 | border-radius: 0.375rem; 143 | } 144 | 145 | .hero-section .buttons a:hover { 146 | background-color: #47b2e4; 147 | } 148 | 149 | /* Hamburger menu styles */ 150 | #menu-toggle { 151 | display: none; 152 | } 153 | 154 | #hamburger-btn { 155 | font-size: 1.8rem; 156 | color: #fff; 157 | cursor: pointer; 158 | display: none; 159 | order: 1; 160 | } 161 | 162 | @media screen and (max-width: 1023px) { 163 | .navbar .logo a { 164 | font-size: 1.5rem; 165 | } 166 | 167 | .links { 168 | position: fixed; 169 | left: -100%; 170 | top: 75px; 171 | width: 100%; 172 | height: 100vh; 173 | padding-top: 50px; 174 | background: #175d69; 175 | flex-direction: column; 176 | transition: 0.3s ease; 177 | } 178 | 179 | .navbar #menu-toggle:checked ~ .links { 180 | left: 0; 181 | } 182 | 183 | .navbar #hamburger-btn { 184 | display: block; 185 | } 186 | 187 | .header .buttons { 188 | display: none; 189 | } 190 | 191 | .hero-section .hero { 192 | max-width: 100%; 193 | text-align: center; 194 | } 195 | 196 | .hero-section img { 197 | display: none; 198 | } 199 | } 200 | 201 | @media screen and (max-width: 767px) { 202 | .navbar .logo a { 203 | font-size: 1.2rem; 204 | } 205 | 206 | .navbar .links { 207 | top: 60px; 208 | } 209 | 210 | .hero-section .hero h2 { 211 | font-size: 2rem; 212 | } 213 | 214 | .hero-section .hero p { 215 | font-size: 1rem; 216 | } 217 | 218 | .hero-section .buttons a { 219 | padding: 10px 20px; 220 | } 221 | } -------------------------------------------------------------------------------- /JAVA/CircularQueue.java: -------------------------------------------------------------------------------- 1 | // Description 2 | // A circular queue is a data structure that uses a fixed-size array to store elements, 3 | // and it supports both enqueue (add elements) and dequeue (remove elements) operations. 4 | // The circular queue overcomes the limitation of a regular queue, where the queue becomes 5 | // full after a certain number of elements are added, making it inefficient for long-running applications. 6 | 7 | // Implementation 8 | 9 | public class CircularQueue { 10 | private int[] elements; 11 | private int front; // Index of the front element 12 | private int rear; // Index of the rear element 13 | private int size; // Current number of elements 14 | private int capacity; // Maximum capacity of the queue 15 | 16 | public CircularQueue(int capacity) { 17 | this.capacity = capacity; 18 | this.elements = new int[capacity]; 19 | this.front = 0; 20 | this.rear = -1; // Initially, the queue is empty 21 | this.size = 0; 22 | } 23 | 24 | public boolean isEmpty() { 25 | return size == 0; 26 | } 27 | 28 | public boolean isFull() { 29 | return size == capacity; 30 | } 31 | 32 | public int size() { 33 | return size; 34 | } 35 | 36 | public void enqueue(int item) { 37 | if (isFull()) { 38 | System.out.println("Queue is full. Cannot enqueue."); 39 | return; 40 | } 41 | 42 | rear = (rear + 1) % capacity; // Wrap around if the rear pointer goes beyond the array size 43 | elements[rear] = item; 44 | size++; 45 | } 46 | 47 | public int dequeue() { 48 | if (isEmpty()) { 49 | System.out.println("Queue is empty. Cannot dequeue."); 50 | return -1; // You can choose a different error code or handle it differently 51 | } 52 | 53 | int item = elements[front]; 54 | front = (front + 1) % capacity; // Wrap around if the front pointer goes beyond the array size 55 | size--; 56 | return item; 57 | } 58 | 59 | public int peek() { 60 | if (isEmpty()) { 61 | System.out.println("Queue is empty."); 62 | return -1; // You can choose a different error code or handle it differently 63 | } 64 | return elements[front]; 65 | } 66 | 67 | public void display() { 68 | if (isEmpty()) { 69 | System.out.println("Queue is empty."); 70 | return; 71 | } 72 | 73 | int current = front; 74 | for (int i = 0; i < size; i++) { 75 | System.out.print(elements[current] + " "); 76 | current = (current + 1) % capacity; 77 | } 78 | System.out.println(); 79 | } 80 | 81 | public static void main(String[] args) { 82 | CircularQueue queue = new CircularQueue(5); 83 | 84 | queue.enqueue(1); 85 | queue.enqueue(2); 86 | queue.enqueue(3); 87 | queue.enqueue(4); 88 | queue.enqueue(5); 89 | 90 | System.out.print("Queue elements: "); 91 | queue.display(); 92 | 93 | System.out.println("Dequeued item: " + queue.dequeue()); 94 | System.out.println("Dequeued item: " + queue.dequeue()); 95 | 96 | System.out.print("Queue elements after dequeuing: "); 97 | queue.display(); 98 | 99 | queue.enqueue(6); 100 | queue.enqueue(7); 101 | 102 | System.out.print("Queue elements after enqueuing: "); 103 | queue.display(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /JAVA/Cyclesort.java: -------------------------------------------------------------------------------- 1 | // Online Java Compiler 2 | // Use this editor to write, compile and run your Java code online 3 | import java.util.Arrays; 4 | 5 | class Cyclesort{ 6 | public static void main(String[] args) { 7 | int[] arr={3,5,2,1,4}; 8 | cyclicsort(arr); 9 | System.out.println(Arrays.toString(arr)); 10 | } 11 | static void cyclicsort(int[] arr){ 12 | int i=0; 13 | while(i "); 60 | current = current.next; 61 | } 62 | System.out.println("null"); 63 | } 64 | 65 | public static void main(String[] args) { 66 | System.out.println("Enter the first sorted list:"); 67 | ListNode l1 = createList(); 68 | System.out.println("Enter the second sorted list:"); 69 | ListNode l2 = createList(); 70 | 71 | System.out.println("Merged List:"); 72 | ListNode mergedList = merge(l1, l2); 73 | printList(mergedList); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /JAVA/SmallestMissingElement.java: -------------------------------------------------------------------------------- 1 | public class SmallestMissingElement { 2 | public static void main(String[] args) { 3 | int[] arr = {0, 1, 2, 3, 4, 6, 7, 8}; 4 | int n = arr.length; 5 | 6 | System.out.println("The smallest missing element is: " + findSmallestMissing(arr, 0, n - 1)); 7 | } 8 | 9 | public static int findSmallestMissing(int[] arr, int start, int end) { 10 | if (start > end) { 11 | return start; 12 | } 13 | 14 | int mid = start + (end - start) / 2; 15 | 16 | if (arr[mid] == mid) { 17 | return findSmallestMissing(arr, mid + 1, end); 18 | } else { 19 | // Else, it's on the left side. 20 | return findSmallestMissing(arr, start, mid - 1); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /JAVA/SudokuSolver,java: -------------------------------------------------------------------------------- 1 | package Backtracking; 2 | 3 | public class SudokuSolver { 4 | public static void main(String[] args) { 5 | int[][] board = { 6 | { 8, 0, 0, 0, 0, 0, 0, 0, 0 }, 7 | { 0, 0, 3, 6, 0, 0, 0, 0, 0 }, 8 | { 0, 7, 0, 0, 9, 0, 2, 0, 0 }, 9 | { 0, 5, 0, 0, 0, 7, 0, 0, 0 }, 10 | { 0, 0, 0, 0, 4, 5, 7, 0, 0 }, 11 | { 0, 0, 0, 1, 0, 0, 0, 3, 0 }, 12 | { 0, 0, 1, 0, 0, 0, 0, 6, 8 }, 13 | { 0, 0, 8, 5, 0, 0, 0, 1, 0 }, 14 | { 0, 9, 0, 0, 0, 0, 4, 0, 0 } 15 | }; 16 | if(solve(board)){ 17 | display(board); 18 | }else{ 19 | System.out.println("Cannot be Solved"); 20 | } 21 | } 22 | 23 | static boolean solve(int[][] board){ 24 | int n= board.length; 25 | int row=-1; 26 | int col=-1; 27 | 28 | boolean emptyLeft = true; 29 | for (int i = 0; i < n; i++) { 30 | for (int j = 0; j < n; j++) { 31 | if(board[i][j]==0){ 32 | row=i; 33 | col=j; 34 | emptyLeft =false; 35 | } 36 | } 37 | 38 | if(emptyLeft==false){ 39 | break; 40 | } 41 | 42 | } 43 | if(emptyLeft==true){ 44 | return true; 45 | //sudoku is solved 46 | } 47 | 48 | for (int number = 1; number <= 9; number++) { 49 | if(isSafe(board,row,col,number)){ 50 | board[row][col]=number; 51 | if(solve(board)){ 52 | return true; 53 | }else{ 54 | board[row][col]=0; 55 | } 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | private static void display(int[][] board) { 62 | for(int[] row:board){ 63 | for(int num:row){ 64 | System.out.print(num + " "); 65 | } 66 | System.out.println(); 67 | } 68 | } 69 | 70 | static boolean isSafe(int[][] board,int row, int col, int num){ 71 | for (int i = 0; i < board.length ; i++) { 72 | if(board[row][i]==num){ 73 | return false; 74 | } 75 | } 76 | for (int[] nums: board) { 77 | if(nums[col]==num){ 78 | return false; 79 | } 80 | } 81 | 82 | int sqrt = (int)Math.sqrt(board.length); 83 | int rowStart = row - row%sqrt; 84 | int colStart = col - col % sqrt; 85 | 86 | for (int r = rowStart; r < rowStart + sqrt ; r++) { 87 | for (int c = colStart; c < colStart + sqrt ; c++) { 88 | if(board[r][c]==num){ 89 | return false; 90 | } 91 | } 92 | } 93 | return true; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 🎉 What is [Hacktoberfest](https://hacktoberfest.com)? 3 | 4 | 5 | 6 | Hacktoberfest 2023 is a month-long virtual festival celebrating open-source contributions. It's the perfect entry point for newcomers to the world of open source! 7 | 8 | Throughout October 2023, all you need to do is contribute to any open-source project and merge at least four pull requests. Yes, you can choose any project and any type of contribution. You don't need to be an expert coder; it could be a bug fix, an improvement, or even a documentation update! 9 | 10 | Hacktoberfest welcomes participants from all corners of our global community. Whether you're an experienced developer, a coding enthusiast just starting out, an event organizer, or a company of any size, you can help drive the growth of open source and make positive contributions to an ever-expanding community. People from diverse backgrounds and skill levels are encouraged to take part. 11 | 12 | Hacktoberfest is an inclusive event open to everyone in our global community! 13 | Pull requests can be submitted to any GitHub or GitLab-hosted repository or project. 14 | You can sign up anytime between October 1 and October 31, 2023. 15 | 16 | ## 🤔 Why Should I Contribute? 17 | 18 | Hacktoberfest has a straightforward goal: to promote open source and reward those who contribute to it. 19 | 20 | However, it's not just about the T-shirts and stickers; it's about supporting and celebrating open source while giving back to the community. If you've never contributed to open source before, now is the perfect time to start. Hacktoberfest offers a wide range of contribution opportunities, including plenty suitable for beginners. 21 | 22 | ## 👨‍💻 What Can I Contribute? 23 | 24 | Hacktoberfest is inclusive and open to everyone, regardless of your background or skill level. Whether you're a seasoned developer, a student learning to code, an event host, or a company of any size, you can help foster the growth of open source and make meaningful contributions to a thriving community. 25 | 26 | Contributions don't have to be limited to code; they can include documentation updates or fixing typos. 27 | 28 | You can contribute to any open source project hosted on GitHub.com between October 1 and October 31, 2023. Look for issues labeled with "hacktoberfest" or "good-first-issue" on GitHub; these are typically beginner-friendly and easy to tackle. 29 | 30 | 31 | ## 💻 Quickstart 32 | 33 | - Assign yourself an [issue](https://github.com/Coderich-Community/Hacktoberfest-2023/issues) and fork this repo. For more information read [CONTRIBUTING]. 34 | - Clone repo locally using `git clone https://github.com/Coderich-Community/Hacktoberfest-2023` 35 | - After cloning make sure you create a new branch by using `git checkout -b my-branch` 36 | - Start making edits in the newly created git branch. Firstly, add your name in the file 37 | - Add the modified/created files to the staging using `git add .` 38 | - Commit the changes made into the checked out branch using `git commit -m "commit message"` 39 | - Push the changes using `git push origin my-branch` 40 | 41 | 42 |
43 | 44 | ## ✨ Contributing 45 | 46 | By contributing to this repository, you adhere to the rules in our Here are a few general instructions for people willing to develop onto the codebase. 47 | 48 | ### • Create issues to discuss your ideas with the maintainers 49 | 50 | Creating issues before starting to work on your pull request helps you stay on the right track. Discuss your proposal well with the current maintainers. 51 | 52 | ### • Keep the code clean 53 | 54 | Follow the code formatting standards of the repository by referring to existing source files. 55 | 56 | ### • Comments are the best 57 | 58 | Make it clear what hacks you've used to keep this website afloat. Your work needs to be understood first, before getting appreciated. 59 | 60 | ### • Keep the Contributors section up-to-date 61 | 62 | To display your contributions to visitors and future contributors. 63 | 64 |
65 | 66 | ## Thanks To Our Valuable Contributors 👾 :handshake: 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | sc 2 | --------------------------------------------------------------------------------