text stringlengths 183 150k | path stringlengths 15 112 | bucket stringclasses 4
values | source stringclasses 14
values | group stringclasses 121
values | spdx stringclasses 11
values | repo_license stringclasses 11
values | commit stringclasses 13
values | lang stringclasses 4
values | def_heavy bool 1
class | comment_ratio float64 0 1 | restricted bool 2
classes | fresh bool 1
class | n_bytes int64 183 150k | n_tokens int64 -1 -1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/**
* @file
* \brief Program to compute the [QR
* decomposition](https://en.wikipedia.org/wiki/QR_decomposition) of a given
* matrix.
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "qr_decompose.h"
/**
* main functio... | thealgorithms-c/numerical_methods/qr_decomposition.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.217 | false | false | 1,948 | -1 |
int diff(const int* i, const int* j)
{
return *i - *j;
}
// Sorting.
// Runtime: O(n*log(n))
// Space: O(1)
int hIndex(int* citations, int citationsSize){
qsort(citations, citationsSize, sizeof(int), (int(*) (const void*, const void*)) diff);
for(int i = 0; i < citationsSize; i++){
if (citations... | thealgorithms-c/leetcode/src/274.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.188 | false | false | 418 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
// Depth first search approach.
// Runtime: O(n)
// Space: O(1)
bool checkIsBst(struct TreeNode* node, bool leftBoundInf, int leftBound, bool rightBoundInf, int rightBou... | thealgorithms-c/leetcode/src/98.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.5 | false | false | 726 | -1 |
/**
* @file
* @brief [Modified binary search algorithm](https://arxiv.org/abs/1406.1677)
*/
#include <stdio.h>
#include <stdlib.h>
/** This function does Binary search for `x` in `i`-th row from `j_low` to
* `j_high`.
* @param mat 2D matrix to search within
* @param i row to search in
* @param j_low start colum... | thealgorithms-c/searching/modified_binary_search.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.324 | false | false | 3,312 | -1 |
/**
* @file
* @brief [Longest Common
* Subsequence](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem)
* algorithm
* @details
* From Wikipedia: The longest common subsequence (LCS) problem is the problem
* of finding the longest subsequence common to all sequences in a set of
* sequences (often j... | thealgorithms-c/dynamic_programming/lcs.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.333 | false | false | 3,757 | -1 |
int compare(const void* i, const void* j)
{
return *((int*)i) - *((int*)j);
}
// Greedy + sorting
// Runtime: O(n*log(n))
// Space: O(1)
int maxIceCream(int* costs, int costsSize, int coins){
qsort(costs, costsSize, sizeof(int), compare);
int result = 0;
int leftCoins = coins;
for (int i = 0; i < ... | thealgorithms-c/leetcode/src/1833.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.15 | false | false | 479 | -1 |
/**
* @file
*
* @details
* Circular [Doubly Linked
* List](https://en.wikipedia.org/wiki/Doubly_linked_list) combines the
* properties of a doubly linked list and a circular linked list in which two
* consecutive elements are linked or connected by the previous. Next, the
* pointer and the last node point to th... | thealgorithms-c/data_structures/linked_list/circular_doubly_linked_list.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.309 | false | false | 7,579 | -1 |
/**
* @file
* @author [Dhruv Pasricha](https://github.com/DhruvPasricha)
* @brief [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) implementation
* @details
* Heap-sort is a comparison-based sorting algorithm.
* Heap-sort can be thought of as an improved selection sort:
* like selection sort, heap sort divide... | thealgorithms-c/sorting/heap_sort_2.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.496 | false | false | 3,822 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
void recursiveSolve(struct TreeNode* node, int* result, int minVal, int maxVal){
if (node ... | thealgorithms-c/leetcode/src/1026.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.5 | false | false | 1,011 | -1 |
/**
* @addtogroup hash Hash algorithms
* @{
* @file hash_crc32.c
* @author [Christian Bender](https://github.com/christianbender)
* @brief 32-bit [CRC
* hash](https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm)
* algorithm
*/
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
/**
... | thealgorithms-c/hash/hash_crc32.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.453 | false | false | 1,176 | -1 |
#define max(x,y)(((x)>(y))?(x):(y))
const int notCalculated = -2;
const int notValid = -1;
int getEndValidIndexFromDp(int* dp, char* s, int index, int lenS){
if (index >= lenS){
return notValid;
}
if (dp[index] == notCalculated){
dp[index] = getEndValidIndex(dp, s, index, lenS);
}
... | thealgorithms-c/leetcode/src/32.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.085 | false | false | 1,498 | -1 |
#define min(a,b) (((a)<(b))?(a):(b))
// Dynamic programming.
// Runtime O(n*n)
// Space O(n)
int minFallingPathSum(int** matrix, int matrixSize, int* matrixColSize){
int* dp = calloc(matrixSize, sizeof(int));
for (int i = 0; i < matrixSize; i++){
int* nextDp = calloc(matrixSize, sizeof(int));
... | thealgorithms-c/leetcode/src/931.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.207 | false | false | 988 | -1 |
#include <stdio.h>
#include <stdlib.h>
void longestSub(int *ARRAY, int ARRAY_LENGTH, int **RESULT, int *RESULT_LENGTH)
{ // RESULT and RESULT_LENGTH will be modified by their pointers
if (ARRAY_LENGTH <= 1)
{
*RESULT = ARRAY;
*RESULT_LENGTH = ARRAY_LENGTH;
}
else
{
int PIV... | thealgorithms-c/misc/longest_subsequence.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.071 | false | false | 3,199 | -1 |
/**
* \file
* \brief [Problem 16](https://projecteuler.net/problem=16) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/** Main function */
int main(int argc, char **argv)
{
const double tmp = log(10) / log(2); /* r... | thealgorithms-c/project_euler/problem_16/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_16 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.245 | false | false | 1,592 | -1 |
/**
* \file
* \brief [Problem 9](https://projecteuler.net/problem=9) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*
Problem Statement:
A Pythagorean triplet is a set of three natural numbers, \f$a < b < c\f$,
for which, \f$a^2 + b^2 = c^2\f$. For example, \f$3^2 + 4^2 = 9 + 16 = 25 =
5^2\f... | thealgorithms-c/project_euler/problem_9/sol2.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_9 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.243 | false | false | 1,067 | -1 |
/**
* @file
* @brief Implementation of [merge
* sort](https://en.wikipedia.org/wiki/Merge_sort) algorithm
*/
#include <stdio.h>
#include <stdlib.h>
/**
* @addtogroup sorting Sorting algorithms
* @{
*/
/** Swap two integer variables
* @param [in,out] a pointer to first variable
* @param [in,out] b pointer to s... | thealgorithms-c/sorting/merge_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.266 | false | false | 2,715 | -1 |
/*
* brute force approach
* time complexity: O(mn)
*/
int strStr(char *haystack, char *needle)
{
int i = 0;
int j = 0;
int k = 0;
int hlen = 0;
int nlen = 0;
if (needle == NULL || *needle == 0)
return 0;
if (haystack == NULL || *haystack == 0)
return -1;
hlen = strl... | thealgorithms-c/leetcode/src/28.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.139 | false | false | 2,293 | -1 |
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ARRAY = NULL, ARRAY_LENGTH, i, TEMPORARY_ELEMENT, isSorted = 0;
float MEAN = 0, VARIANCE = 0, STAND;
printf("Enter no. for Random Numbers :");
scanf("%d", &ARRAY_LENGTH);
ARRAY = (int *)realloc(
ARRAY,
ARRAY... | thealgorithms-c/numerical_methods/variance.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.087 | false | false | 1,849 | -1 |
/**
* @file
* \brief Compute factorial of arbitrarily large numbers by
* storing individual digits in a byte.
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/**
* dynamically large number
*/
typedef struct _large_num
{
char *digits; ... | thealgorithms-c/math/factorial_large_number.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.312 | false | false | 2,816 | -1 |
#include <stdio.h>
#include <stdlib.h>
#define SHRINK 1.3 // suggested shrink factor value
void sort(int *numbers, int size)
{
int gap = size;
while (gap > 1) // gap = 1 means that the array is sorted
{
gap = gap / SHRINK;
int i = 0;
while ((i + gap) < size)
{ // similiar... | thealgorithms-c/sorting/comb_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.07 | false | false | 1,069 | -1 |
/**
* @file
* @author [NVombat](https://github.com/NVombat)
* @brief Server-side implementation of [Remote Command
* Execution Using
* UDP](https://www.imperva.com/learn/ddos/udp-user-datagram-protocol/)
* @see remote_command_exec_udp_server.c
*
* @details
* The algorithm is based on the simple UDP client and ... | thealgorithms-c/client_server/remote_command_exec_udp_server.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.716 | false | false | 6,402 | -1 |
struct TreeNode *buildBST(struct ListNode *head, struct ListNode *tail)
{
if (head == tail)
return NULL;
struct ListNode *slow = head, *fast = head;
while (fast != tail && fast->next != tail)
{
fast = fast->next->next;
slow = slow->next;
}
struct TreeNode *node = malloc(s... | thealgorithms-c/leetcode/src/109.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 618 | -1 |
void rotate(int *nums, int numsSize, int k)
{
for (int i = 1; i <= k; i++)
{
int j;
int lastElement;
lastElement = nums[numsSize - 1];
for (j = numsSize - 1; j > 0; j--)
{
nums[j] = nums[j - 1];
}
nums[0] = lastElement;
}
} | thealgorithms-c/leetcode/src/189.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 303 | -1 |
// sorting of array list using Radix sort
#include <stdio.h>
#include <stdlib.h>
#define range 10 // Range for integers is 10 as digits range from 0-9
// Utility function to get the maximum value in ar[]
int MAX(int *ar, int size)
{
int i, max = ar[0];
for (i = 0; i < size; i++)
{
if (ar[i] > max... | thealgorithms-c/sorting/radix_sort_2.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.177 | false | false | 2,217 | -1 |
/**
* @file
* @author [Krishna Vedala](https://github.com/kvedala)
* @brief Implementation of
* [Spirograph](https://en.wikipedia.org/wiki/Spirograph)
*
* @details
* Implementation of the program is based on the geometry shown in the figure
* below:
*
* <a
* href="https://commons.wikimedia.org/wiki/File:Reso... | thealgorithms-c/graphics/spirograph.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.363 | false | false | 8,604 | -1 |
/**
* @addtogroup hash Hash algorithms
* @{
* @file hash_sdbm.c
* @author [Christian Bender](https://github.com/christianbender)
* @brief [SDBM hash algorithm](http://www.cse.yorku.ca/~oz/hash.html)
*/
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
/**
* @brief SDBM algorithm implementation
*
* ... | thealgorithms-c/hash/hash_sdbm.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.478 | false | false | 1,015 | -1 |
#ifndef __LIST__
#define __LIST__
#define L List_T
typedef struct L *L;
struct L
{
void *val;
L next;
};
extern L List_init(void);
extern L List_push(L list, void *val);
extern int List_length(L list);
extern void **List_toArray(L list);
extern L List_append(L list, L tail);
extern L List_list(L list, void *... | thealgorithms-c/data_structures/list/list.h | algorithms | thealgorithms-c | thealgorithms-c/data_structures/list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.3 | false | false | 417 | -1 |
/**
* \file
* \brief [Kohonen self organizing
* map](https://en.wikipedia.org/wiki/Self-organizing_map) (topological map)
*
* This example implements a powerful unsupervised learning algorithm called as
* a self organizing map. The algorithm creates a connected network of weights
* that closely follows the given... | thealgorithms-c/machine_learning/kohonen_som_topology.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.4 | false | false | 22,802 | -1 |
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
// Collect maxes on each row and each column.
// Runtime: O(n * n)
// Space: O(n)
int maxIncreaseKeepingSkyline(int** grid, int gridSize, int* gridColSize){
int* rowsMaxs = calloc(gridSize, sizeof(int));
int* colsMaxs = calloc(gridSize, ... | thealgorithms-c/leetcode/src/807.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.222 | false | false | 913 | -1 |
/**
* @file
* @brief [Patience Sort](https://en.wikipedia.org/wiki/Patience_sorting)
* @details From Wikipedia:
* In computer science, patience sorting is a sorting algorithm inspired by, and named after, the card game patience.
* Given an array of n elements from some totally ordered domain, consider this array a... | thealgorithms-c/sorting/patience_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.384 | false | false | 5,138 | -1 |
bool isleaf(struct TreeNode *root)
{
return root->left == NULL && root->right == NULL;
}
int sumOfLeftLeaves(struct TreeNode *root)
{
if (root == NULL)
return 0;
if (root->left)
{
if (isleaf(root->left))
return root->left->val + sumOfLeftLeaves(root->right);
}
return... | thealgorithms-c/leetcode/src/404.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 383 | -1 |
#include <stdio.h>
#include <stdlib.h>
int linearsearch(int *arr, int size, int val)
{
int i;
for (i = 0; i < size; i++)
{
if (arr[i] == val)
return 1;
}
return 0;
}
int main()
{
int n, i, v;
printf("Enter the size of the array:\n");
scanf("%d", &n); // Taking inpu... | thealgorithms-c/searching/linear_search.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.097 | false | false | 898 | -1 |
/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
// Calculating ones on each row and column.
// Runtime: O(n * m)
// Space: O(n + m)
int** ones... | thealgorithms-c/leetcode/src/2482.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.278 | false | false | 1,226 | -1 |
int max(int a, int b) { return a >= b ? a : b; }
int height(struct TreeNode *root)
{
if (root == NULL)
return 0;
else
return 1 + max(height(root->left), height(root->right));
}
bool isBalanced(struct TreeNode *root)
{
if (root == NULL)
return 1;
int left = height(root->left);
... | thealgorithms-c/leetcode/src/110.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 457 | -1 |
/**
* @addtogroup hash Hash algorithms
* @{
* @file hash_djb2.c
* @author [Christian Bender](https://github.com/christianbender)
* @brief [DJB2 hash algorithm](http://www.cse.yorku.ca/~oz/hash.html)
*/
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
/**
* @brief DJB2 algorithm implementation
*
* ... | thealgorithms-c/hash/hash_djb2.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.478 | false | false | 1,017 | -1 |
#include <stdio.h>
#include <string.h> // we include the library string.h to the use of string
void saisie(
char *cpointeur); // Prototypes of the three functions used in the program
int compte(char *s);
char *miroir(char *s);
int main(int argc, char *argv[])
{
char chaine[20];
saisie(chaine);
print... | thealgorithms-c/misc/mirror.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.107 | false | false | 1,434 | -1 |
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head)
{
struct ListNode *fast = head, *slow = head;
while (slow && fast && fast->next)
{
fast = fast->next->next;
slow = slow->next;
i... | thealgorithms-c/leetcode/src/141.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.368 | false | false | 388 | -1 |
/**
* \file
* \brief [Problem 7](https://projecteuler.net/problem=7) solution.
* @see Another version: problem_7/sol2.c
*/
#include <stdio.h>
#include <stdlib.h>
/** Main function
* @return 0 on exit
*/
int main(void)
{
char *sieve;
size_t i;
unsigned count = 0;
size_t n = 1000000;
const unsi... | thealgorithms-c/project_euler/problem_7/sol.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_7 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.263 | false | false | 767 | -1 |
/**
* @file
* @brief A basic unbalanced binary search tree implementation in C.
* @details The implementation has the following functionalities implemented:
* - Insertion
* - Deletion
* - Search by key value
* - Listing of node keys in order of value (from left to right)
*/
#include <stdio.h>
#include <stdlib.h... | thealgorithms-c/data_structures/binary_trees/binary_search_tree.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/binary_trees | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.309 | false | false | 8,197 | -1 |
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *removeNthFromEnd(struct ListNode *head, int n) {
struct ListNode entry, *p_free, *p = head;
int i, sz = 0;
entry.next = head;
while (p != NULL) {
p = p->next;
... | thealgorithms-c/leetcode/src/19.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.269 | false | false | 565 | -1 |
/**
* \file
* \brief [Problem 1](https://projecteuler.net/problem=1) solution
* \details
* An Efficient code to print all the sum of all numbers that are multiples of 3
* & 5 below N.
*/
#include <stdio.h>
/** Main function */
int main()
{
int t;
printf("Enter number of times you want to try");
scan... | thealgorithms-c/project_euler/problem_1/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_1 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.333 | false | false | 919 | -1 |
/**
* @file
* @brief Finding Fibonacci number of any `n` number using [Binet's closed form formula](https://en.wikipedia.org/wiki/Fibonacci_number#Binet's_formula)
* compute \f$f_{nth}\f$ Fibonacci number using the binet's formula:
* Fn = 1√5 * (1+√5 / 2)^n+1 − 1√5 * (1−√5 / 2)^n+1
* @author [GrandSir](https://git... | thealgorithms-c/math/fibonacci_formula.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.519 | false | false | 1,630 | -1 |
/**
* \file
* \brief [Problem 20](https://projecteuler.net/problem=20) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*
* Implementation uses a custom `big_int` structure that can store arbitrarily
* large integer numbers.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/**
* store... | thealgorithms-c/project_euler/problem_20/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_20 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.3 | false | false | 4,562 | -1 |
/*
* Algorithm : Bucket Sort
* Time-Complexity : O(n)
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define NARRAY 8 /* array size */
#define NBUCKET 5 /* bucket size */
#define INTERVAL 10 /* bucket range */
struct Node
{
int data;
struct Node *next;
};
void BucketSort(int arr[]);
st... | thealgorithms-c/sorting/bucket_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.149 | false | false | 4,350 | -1 |
#define max(a,b) (((a)>(b))?(a):(b))
bool equalSubstrings(char* text, int firstIndex, int secondIndex, int length){
for (int i = 0; i < length; i++){
if (text[firstIndex + i] != text[secondIndex + i]){
return false;
}
}
return true;
}
int longestDecompositionDpCached(char* tex... | thealgorithms-c/leetcode/src/1147.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.103 | false | false | 1,291 | -1 |
struct TreeNode *newNode(int item)
{
struct TreeNode *node = (struct TreeNode *)malloc(sizeof(struct TreeNode));
node->val = item;
node->left = node->right = NULL;
return node;
}
struct TreeNode *mergeTrees(struct TreeNode *t1, struct TreeNode *t2)
{
if (t1 == NULL && t2 == NULL)
return NUL... | thealgorithms-c/leetcode/src/617.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 675 | -1 |
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
bool check_sorted(int *a, int n)
{
while (--n >= 1)
{
if (a[n] < a[n - 1])
return false;
}
return true;
}
void shuffle(int *a, int n)
{
int i, t, r;
for (i = 0; i < n; i++)
{
t = a[i];
r = rand(... | thealgorithms-c/sorting/bogo_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.075 | false | false | 712 | -1 |
// Use monotonic stack.
// Keep the stack of monotonically increasing price and index.
// Runtime: O(n)
// Space: O(n)
typedef struct stack{
int price;
int index;
struct stack* previous;
} Stack;
typedef struct {
int index;
Stack* stackPointer;
Stack* sentry;
} StockSpanner;
StockSpanner* s... | thealgorithms-c/leetcode/src/901.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.182 | false | false | 1,729 | -1 |
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) DIGITEO - 2010 - Allan CORNET
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally ... | thealgorithms-c/client_server/fork.h | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.28 | false | false | 11,374 | -1 |
#include <stdio.h>
// Function to perform Ternary Search
int ternarySearch(int l, int r, int key, int ar[])
{
if (r >= l)
{
// Find the mid1 and mid2
int mid1 = l + (r - l) / 3;
int mid2 = r - (r - l) / 3;
// Check if key is present at any mid
if (ar[mid1] == key)
... | thealgorithms-c/searching/ternary_search.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.373 | false | false | 1,782 | -1 |
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *head1 = NULL;
struct node *head2 = NULL;
///// MAIN ALGORITHMIC FUNCTION to MERGE the two input linked lists ///////
void merge()
{
struct node *temp1 = head1;
struct node *temp2 = head2;
struct nod... | thealgorithms-c/data_structures/linked_list/merge_linked_lists.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.22 | false | false | 2,792 | -1 |
int divide(int dividend, int divisor)
{
int sign = 1;
long int output = 0;
if (dividend < 0)
{
sign *= -1;
}
else
{
dividend *= -1;
}
if (divisor < 0)
{
sign *= -1;
}
else
{
divisor *= -1;
}
while (dividend <= divisor)
{
... | thealgorithms-c/leetcode/src/29.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 784 | -1 |
int** initSet(int size){
int** result = (int**) malloc(size * sizeof(int*));
for (int i = 0; i < size; i++) {
result[i] = (int*)calloc(size, sizeof(int));
}
return result;
}
// Returns the id of triplet which the point (i, j) belongs to
int getTripletId(int i, int j){
return (i / 3... | thealgorithms-c/leetcode/src/37.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.167 | false | false | 3,082 | -1 |
/* Circularly Linked List (Basic Operations) - Program to create a Circularly linked list abstract data type and perform various operations on it (Variable first and last declared globally) */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define NULL 0
/* Assume that the data portion of each node con... | thealgorithms-c/data_structures/linked_list/circular_linked_list.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.085 | false | false | 3,202 | -1 |
/**
* Letter Combinations of a Phone Number problem
* The algorithm determines the final size of the return array (combs) and allocates
* corresponding letter for each element, assuming that the return array is alphabetically sorted.
* It does so by running two loops for each letter:
* - the first loop determine... | thealgorithms-c/leetcode/src/17.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.214 | false | false | 2,440 | -1 |
/**
* Kyler Smith, 2017
* Stack data structure implementation.
*/
////////////////////////////////////////////////////////////////////////////////
// INCLUDES
#include <stdio.h>
#include <stdlib.h>
////////////////////////////////////////////////////////////////////////////////
// MACROS: CONSTANTS
//////////////... | thealgorithms-c/data_structures/stack.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.303 | false | false | 3,039 | -1 |
#include <stdio.h>
#include <stdlib.h>
#define MAXBITS 100
int main()
{
// input of the user
int inputNumber;
// for the remainder
int re;
// contains the bits 0/1
int bits[MAXBITS];
// for the loops
int j;
int i = 0;
printf("\t\tConverter decimal --> binary\n\n");
// ... | thealgorithms-c/conversions/decimal_to_binary.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.298 | false | false | 1,141 | -1 |
// C program to find LCM of two numbers
/*
suppose we have two numbers a and b.
Property: Since product of LCM and GCD of two numbers are equal to product
of that number itself. i.e, LCM(a,b)*GCD(a,b)=a*b. So,here we first find the
GCD of two numbers and using above property we find LCM of that two number... | thealgorithms-c/math/lcm.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.265 | false | false | 848 | -1 |
//using the binary search method is one of the efficient ones for this problem statement.
int mySqrt(int x){
int start=0;
int end=x;
long long int ans=0;
while(start <= end){
long long int mid=(start+end)/2;
long long int val=mid*mid;
if( val == x){
... | thealgorithms-c/leetcode/src/69.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.13 | false | false | 789 | -1 |
/**
* @file
* @brief Program to perform [binary
* search](https://en.wikipedia.org/wiki/Binary_search_algorithm) of a target
* value in a given *sorted* array.
* @authors [James McDermott](https://github.com/theycallmemac) - recursive
* algorithm
* @authors [Krishna Vedala](https://github.com/kvedala) - iterativ... | thealgorithms-c/searching/binary_search.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.432 | false | false | 2,799 | -1 |
bool isPalindrome(char *s)
{
int start = 0, end = strlen(s) - 1;
while (start < end)
{
if (!isalpha(s[start]) && !isalnum(s[start]))
{
start++;
}
else if (!isalpha(s[end]) && !isalnum(s[end]))
{
end--;
}
else
{
... | thealgorithms-c/leetcode/src/125.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 515 | -1 |
/**
* \file
* \brief [Problem 8](https://projecteuler.net/problem=8) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
#include <stdlib.h>
/** Compute the product of two numbers in a file
*
* \param[in] fp pointer to file that is already open
* \param[in] start_pos line numbe... | thealgorithms-c/project_euler/problem_8/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_8 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.347 | false | false | 3,342 | -1 |
/**
* \file
* \brief [Problem 5](https://projecteuler.net/problem=5) solution (Fastest).
* @details Solution is the LCM of all numbers between 1 and 20.
*
* \see Slowest: problem_5/sol1.c
* \see Slower: problem_5/sol2.c
*/
#include <stdio.h>
/** Compute [Greatest Common Divisor
* (GCD)](https://en.wikipedia.or... | thealgorithms-c/project_euler/problem_5/sol3.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_5 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.439 | false | false | 1,280 | -1 |
int cmpval(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int findDuplicate(int *nums, int numsSize)
{
int i;
qsort(nums, numsSize, sizeof(int), cmpval);
for (i = 0; i < numsSize - 1; i++)
{
if (nums[i] == nums[i + 1])
return nums[i];
}
return nums[i];
}
| thealgorithms-c/leetcode/src/287.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 316 | -1 |
/**
* @file
* @brief
* [Non-Preemptive Priority
* Scheduling](https://en.wikipedia.org/wiki/Scheduling_(computing))
* is a scheduling algorithm that selects the tasks to execute based on
* priority.
*
* @details
* In this algorithm, processes are executed according to their
* priority. The process with the hi... | thealgorithms-c/process_scheduling_algorithms/non_preemptive_priority_scheduling.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.346 | false | false | 9,585 | -1 |
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
int intersectionSize(int p11, int p12, int p21, int p22){
if (p11 >= p22 || p12 <= p21){
return 0;
}
if (p11 < p21){
return min(p12 - p21, p22 - p21);
}
return min(p22 - p11, p12 - p11);
}
// Calculation area of the A, then area of the B ... | thealgorithms-c/leetcode/src/223.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.211 | false | false | 720 | -1 |
#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
int partition(int arr[], int low, int high)
{
int pivot = arr[low];
int i = low - 1, j = high + 1;
while (1)
{
/* Find leftmost element >= pivot */
do
{
... | thealgorithms-c/sorting/partition_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.115 | false | false | 1,276 | -1 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap(char *left, char *right)
{
char temp = *left;
*left = *right;
*right = temp;
}
int compare(const void *a, const void *b) { return (*(char *)a - *(char *)b); }
void PrintSortedPermutations(char *str)
{
int strSize = strlen(str);
... | thealgorithms-c/misc/lexicographic_permutations.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.203 | false | false | 1,669 | -1 |
// A number is called as Armstrong number if sum of cubes of digits of number is
// equal to the number itself.
// For Example 153 is an Armstrong number because 153 = 1³+5³+3³.
#include <stdio.h>
// Function to calculate x raised to the power y
int power(int x, unsigned int y)
{
if (y == 0)
return 1;
... | thealgorithms-c/math/armstrong_number.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.19 | false | false | 1,241 | -1 |
/**
* \file
* \brief [Problem 22](https://projecteuler.net/problem=22) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef _OPENMP
#include <omp.h>
#endif
#define MAX_NAMES 6000 /**< Maximum number of names to store... | thealgorithms-c/project_euler/problem_22/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_22 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.284 | false | false | 3,786 | -1 |
#include <stdio.h>
#include <string.h>
#define NUM_OF_CHARS 256
int max(int a, int b) { return (a > b) ? a : b; }
void computeArray(char *pattern, int size, int arr[NUM_OF_CHARS])
{
int i;
for (i = 0; i < NUM_OF_CHARS; i++) arr[i] = -1;
/* Fill the actual value of last occurrence of a character */
f... | thealgorithms-c/searching/pattern_search/boyer_moore_search.c | algorithms | thealgorithms-c | thealgorithms-c/searching/pattern_search | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.102 | false | false | 1,433 | -1 |
void visitRooms(int key, int** rooms, int roomsSize, int* roomsColSize, int* visitedRooms){
if (visitedRooms[key] == 1){
return;
}
visitedRooms[key] = 1;
for (int i = 0; i < roomsColSize[key]; i++){
visitRooms(rooms[key][i], rooms, roomsSize, roomsColSize, visitedRooms);
}
}
// Dep... | thealgorithms-c/leetcode/src/841.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.13 | false | false | 765 | -1 |
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 40 // Assume 40 nodes at max in graph
#define INT_MIN 0
// A vertex of the graph
struct node
{
int vertex;
struct node *next;
};
// Some declarations
struct node *createNode(int v);
struct Graph
{
int numVertices;
int *visited;
struct node *
... | thealgorithms-c/data_structures/graphs/strongly_connected_components.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.144 | false | false | 5,941 | -1 |
/**
* \file
* \brief [Problem 15](https://projecteuler.net/problem=15) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/**
* At every node, there are 2 possible ways to move -> down or right.
* Since it is a square grid, there are in a... | thealgorithms-c/project_euler/problem_15/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_15 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.457 | false | false | 957 | -1 |
/**
* @file
* @brief Conversion of temperature in degrees from [Celsius](https://en.wikipedia.org/wiki/Celsius)
* to [Fahrenheit](https://en.wikipedia.org/wiki/Fahrenheit).
*
* @author [Focusucof](https://github.com/Focusucof)
*/
#include <assert.h> /// for assert
#include <stdio.h> /// for IO operations
/**
... | thealgorithms-c/conversions/celsius_to_fahrenheit.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.419 | false | false | 1,753 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
#define max(a,b) (((a)>(b))?(a):(b))
int recursiveSolve(struct TreeNode* node, int* result){
if (node == NULL){
return 0;
}
int leftSum = max(recur... | thealgorithms-c/leetcode/src/124.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.5 | false | false | 943 | -1 |
int rangeSumBST(struct TreeNode *root, int L, int R)
{
if (root == NULL)
{
return 0;
}
else if (root->val >= L && root->val <= R)
{
return root->val + rangeSumBST(root->left, L, R) +
rangeSumBST(root->right, L, R);
}
else
{
return rangeSumBST(root->... | thealgorithms-c/leetcode/src/938.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 374 | -1 |
/**
* @file
* @brief Implementation of [Addition of two polynomials]
* (https://en.wikipedia.org/wiki/Polynomial#Addition)
* @author [Ankita Roy Chowdhury](https://github.com/Ankita19ms0010)
* @details
* This code takes two polynomials as input
* and prints their sum using linked list.
* The polynomials must be... | thealgorithms-c/misc/poly_add.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.348 | false | false | 8,480 | -1 |
/**
* \file
* \brief [Problem 1](https://projecteuler.net/problem=1) solution.
* This solution is based on the pattern that the successive numbers in the
* series follow: 0+3,+2,+1,+3,+1,+2,+3.
*
* If we list all the natural numbers below 10 that are multiples of 3 or 5,
* we get 3,5,6 and 9. The sum of these mu... | thealgorithms-c/project_euler/problem_1/sol3.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_1 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.231 | false | false | 1,140 | -1 |
/**
* @file
* @brief implementation of [Bubble sort](https://en.wikipedia.org/wiki/Bubble_sort) algorithm
* @details
* worst-case: O(n^2)
* best-case: O(n)
* average-complexity: O(n^2)
* @author Unknown author
* @author [Gabriel Fioravante](https://github.com/northernSage)
*/
#include <stdlib.h> /// for ra... | thealgorithms-c/sorting/bubble_sort_2.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.539 | false | false | 2,054 | -1 |
/**
* @file
* @brief This file contains malloc_dbg, calloc_dbg, free_dbg and printLeaks implementations.
* @author [tinouduart33](https://github.com/tinouduart33)
*/
#include <stdlib.h> /// For the malloc, calloc and free functions.
#include <stdio.h> /// For IO operations (printf).
#include <string.h> /// For the... | thealgorithms-c/developer_tools/malloc_dbg.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.327 | false | false | 8,390 | -1 |
long numberOfWaysForChar(char * s, char c){
long firstBuildingAppearNumber = 0;
long secondBuildingAppearNumber = 0;
long result = 0;
int sLength = strlen(s);
for (int i = 0; i < sLength; i++){
if (s[i] == c){
result += secondBuildingAppearNumber;
firstBuildingA... | thealgorithms-c/leetcode/src/2222.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.25 | false | false | 875 | -1 |
/**
* @file
* @author [sunzhenliang](https://github.com/HiSunzhenliang)
* @brief A-law algorithm for encoding and decoding (16bit pcm <=> a-law).
* This is the implementation of [G.711](https://en.wikipedia.org/wiki/G.711)
* in C.
**/
/**
* Linear input code | Compressed code | Linear output code
* -----------... | thealgorithms-c/audio/alaw.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.546 | false | false | 6,201 | -1 |
int findLengthOfLCIS(int *nums, int numsSize)
{
int maxval = 1, i, count = 1;
if (numsSize == 0)
return 0;
for (i = 1; i < numsSize; i++)
{
if (nums[i] > nums[i - 1])
{
count++;
if (count >= maxval)
maxval = count;
}
else
... | thealgorithms-c/leetcode/src/674.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 388 | -1 |
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int *plusOne(int *digits, int digitsSize, int *returnSize)
{
for (int i = digitsSize - 1; i >= 0; i--)
{
if (digits[i] < 9)
{
digits[i]++;
*returnSize = digitsSize;
return digits... | thealgorithms-c/leetcode/src/66.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.185 | false | false | 639 | -1 |
int maxcmp(int a, int b) { return a >= b ? a : b; }
int maxSubArray(int *nums, int numsSize)
{
int maxSoFar = nums[0], maxEndingHere = nums[0];
for (int i = 1; i < numsSize; i++)
{
maxEndingHere = maxcmp(maxEndingHere + nums[i], nums[i]);
maxSoFar = maxcmp(maxSoFar, maxEndingHere);
}
... | thealgorithms-c/leetcode/src/53.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 342 | -1 |
/**
* @file
* @brief [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance)
* algorithm implementation.
* @details
* In information theory, the Hamming distance between two strings of
* equal length is the number of positions at which the corresponding symbols
* are different.
* @author [Aybars Nazl... | thealgorithms-c/misc/hamming_distance.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.481 | false | false | 1,312 | -1 |
/**
* @file
* @brief [Infix to
* Postfix](https://condor.depaul.edu/ichu/csc415/notes/notes9/Infix.htm)
* Expression Conversion
* @details Convert Infixed expressions to Postfix expression.
* @author [Harsh Karande](https://github.com/harshcut)
*/
// include header files
#include <stdio.h> /// for printf() and... | thealgorithms-c/conversions/infix_to_postfix.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.262 | false | false | 5,503 | -1 |
bool check(int* nums, int numsSize){
if (numsSize == 1) {
return true;
}
bool wasShift = false;
for(int i = 1; i < numsSize; i++) {
if (nums[i - 1] > nums[i]) {
if (wasShift) {
return false;
}
wasShift = true;
}
}
... | thealgorithms-c/leetcode/src/1752.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 388 | -1 |
/**
* \file
* \authors [Krishna Vedala](https://github.com/kvedala)
* \brief Solve a multivariable first order [ordinary differential equation
* (ODEs)](https://en.wikipedia.org/wiki/Ordinary_differential_equation) using
* [midpoint Euler
* method](https://en.wikipedia.org/wiki/Midpoint_method)
*
* \details
* ... | thealgorithms-c/numerical_methods/ode_midpoint_euler.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.488 | false | false | 5,557 | -1 |
/**
* @file
* @author [Timothy Maloney](https://github.com/sl1mb0)
* @brief [Prim's algorithm](https://en.wikipedia.org/wiki/Prim%27s_algorithm)
* implementation in C to find the MST of a weighted, connected graph.
* @details Prim's algorithm uses a greedy approach to generate the MST of a weighted connected graph... | thealgorithms-c/greedy_approach/prim.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.343 | false | false | 4,811 | -1 |
// Binary number to octal number conversion
#include <stdio.h>
// Function that returns the last three digits
int three_digits(int n)
{
int r, d = 0, p = 1;
for (int i = 0; i < 3; i++)
{
r = n % 10;
d += r * p;
p *= 10;
n /= 10;
}
return d;
}
int main(void)
{
i... | thealgorithms-c/conversions/binary_to_octal.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.093 | false | false | 1,088 | -1 |
/**
* \file
* \brief [Problem 7](https://projecteuler.net/problem=7) solution.
* @see Faster version problem_7/sol.c
*/
#include <stdio.h>
/** Main function
* @return 0 on exit
*/
int main()
{
int n;
scanf("%d", &n);
int number_of_prime = 0;
for (int i = 2;; i++)
{
int divisors = 0;
... | thealgorithms-c/project_euler/problem_7/sol2.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_7 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.25 | false | false | 683 | -1 |
/**
* @brief Converts a number from [Binary to Decimal](https://en.wikipedia.org/wiki/Binary-coded_decimal).
* @details
*
* Binary to decimal conversion is a process to convert a number
* having a binary representation to its equivalent decimal representation.
*
* The base of both number systems is different.
*... | thealgorithms-c/conversions/binary_to_decimal.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.557 | false | false | 2,181 | -1 |
// program for stack using array
#include <stdio.h>
void push();
void pop();
void peek();
void update();
void display();
int a[100], top = -1;
int main()
{
int x;
while (1)
{
printf("\n0 or CTRL-C to Exit ");
printf("\n1. Push");
printf("\n2. Pop");
printf("\n3. Peek");
... | thealgorithms-c/data_structures/stack/main.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/stack | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.064 | false | false | 2,084 | -1 |
/**
* @file
* @author [Dhruv Pasricha](https://github.com/DhruvPasricha)
* @brief [Selection Sort](https://en.wikipedia.org/wiki/Selection_sort)
* implementation using recursion.
*/
#include <assert.h> /// for assert
#include <stdio.h> /// for IO operations
#include <stdlib.h> /// for dynamic memory ... | thealgorithms-c/sorting/selection_sort_recursive.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.463 | false | false | 2,444 | -1 |
/**
* \file
* \brief [Problem 25](https://projecteuler.net/problem=25) solution implemented
* using arbitrarily large numbers represented as arrays
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX... | thealgorithms-c/project_euler/problem_25/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_25 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.271 | false | false | 2,993 | -1 |
/* C program to convert Hexadecimal to Octal number system */
#include <stdio.h>
int main()
{
#define MAX_STR_LEN 17
char hex[MAX_STR_LEN];
long long octal, bin, place;
int i = 0, rem, val;
/* Input hexadecimal number from user */
printf("Enter any hexadecimal number: ");
fgets(hex, MAX_STR_L... | thealgorithms-c/conversions/hexadecimal_to_octal.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.05 | false | false | 2,525 | -1 |
#include "stack.h"
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#define T Stack_T
typedef struct elem
{
void *val;
struct elem *next;
} elem_t;
struct T
{
int count;
elem_t *head;
};
/* Initial stack */
T Stack_init(void)
{
T stack;
stack = (T)malloc(sizeof(... | thealgorithms-c/data_structures/stack/stack_linked_list/stack.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/stack | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.158 | false | false | 1,466 | -1 |
/**
* @file
* @brief In mathematics, the [Bisection
* Method](https://en.wikipedia.org/wiki/Bisection_method) is a root-finding
* method that applies to any continuous function for which one knows two values
* with opposite signs.
* @details
* The method consists of repeatedly bisecting the interval
* defined b... | thealgorithms-c/numerical_methods/bisection_method.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.535 | false | false | 3,396 | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.