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 [Problem 10](https://projecteuler.net/problem=10) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
/** Main function */
int main(int argc, char *argv[])
{
long n = 100;
long long sum = 0;
char *sieve = NULL;... | thealgorithms-c/project_euler/problem_10/sol2.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_10 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.312 | false | false | 1,266 | -1 |
/**
* \file
* \brief [Problem 1](https://projecteuler.net/problem=1) solution
*
* 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 multiples is 23.
* Find the sum of all the multiples of 3 or 5 below N.
*
* This solution is based on the pattern tha... | thealgorithms-c/project_euler/problem_1/sol2.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_1 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.5 | false | false | 784 | -1 |
struct ListNode *deleteDuplicates(struct ListNode *head)
{
if (head == NULL)
return NULL;
if (head->next && head->val == head->next->val)
{
/* Remove all duplicate numbers */
while (head->next && head->val == head->next->val)
{
head = head->next;
}
... | thealgorithms-c/leetcode/src/82.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.053 | false | false | 456 | -1 |
#ifndef __DYNAMIC_ARRAY__
#define __DYNAMIC_ARRAY__
#define DEFAULT_CAPACITY 1 << 4
#define INDEX_OUT_OF_BOUNDS NULL
typedef struct dynamic_array
{
void **items;
unsigned size;
unsigned capacity;
} dynamic_array_t;
extern dynamic_array_t *init_dynamic_array();
extern void *add(dynamic_array_t *da, const ... | thealgorithms-c/data_structures/dynamic_array/dynamic_array.h | algorithms | thealgorithms-c | thealgorithms-c/data_structures/dynamic_array | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.278 | false | false | 662 | -1 |
/**
* \file
* \brief [Problem 23](https://projecteuler.net/problem=23) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef _OPENMP
#include <omp.h>
#endif
/**
* Returns:
* -1 if N is deficient
* 1 if N is abundant
* 0 if N is perf... | thealgorithms-c/project_euler/problem_23/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_23 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.36 | false | false | 2,934 | -1 |
/**
* \file
* \brief [Problem 5](https://projecteuler.net/problem=5) solution - Naive
* algorithm (Improved over problem_5/sol1.c)
* @details Little bit improved version of the naive `problem_5/sol1.c`. Since
* the number has to be divisable by 20, we can start at 20 and go in 20 steps.
* Also we don't have to ch... | thealgorithms-c/project_euler/problem_5/sol2.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_5 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.527 | false | false | 1,405 | -1 |
#include <math.h>
#include <stdio.h>
#define ARRAY_SIZE 20
void display(float a[ARRAY_SIZE][ARRAY_SIZE], int n)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j <= n; j++)
{
printf("%.2f \t", a[i][j]);
}
printf("\n");
}
}
float interchange(float m[ARRAY_... | thealgorithms-c/numerical_methods/gauss_elimination.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.031 | false | false | 2,402 | -1 |
// Graph ADT
// Adjacency Matrix Representation
#include "Graph.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct GraphRep
{
int **edges; // adjacency matrix
int nV; // #vertices
int nE; // #edges
} GraphRep;
Graph newGraph(int V)
{
assert(V >= 0);
int i;
... | thealgorithms-c/data_structures/graphs/graph.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.313 | false | false | 3,351 | -1 |
/**
* @file
* @brief Sudoku Solver using recursive implementation of brute-force algorithm
*
* @details
* Given an incomplete N*N Sudoku and asked to solve it using the
* following recursive algorithm:
* 1. Scan the Sudoku from left to right row-wise to search for an empty cell.
* 2. If there are no empty cells... | thealgorithms-c/misc/sudoku_solver.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.43 | false | false | 7,689 | -1 |
/**
* @file
* @brief [Selection sort](https://en.wikipedia.org/wiki/Selection_sort)
* algorithm implementation.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/**
* Swapped two numbers using pointer
* @param first first pointer of first number
* @param second second pointer of s... | thealgorithms-c/sorting/selection_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.386 | false | false | 1,559 | -1 |
#include <stdio.h>
#include <stdlib.h>
/* Link list node */
struct Node
{
int data;
struct Node *next;
};
/* Function to get the middle of the linked list*/
void printMiddle(struct Node *head)
{
struct Node *slow_ptr = head;
struct Node *fast_ptr = head;
if (head != NULL)
{
while (fas... | thealgorithms-c/data_structures/linked_list/middle_element_in_list.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.19 | false | false | 1,378 | -1 |
/*
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *addTwoNumbers(struct ListNode *l1, struct ListNode *l2)
{
struct ListNode *head = NULL;
struct ListNode *walk = NULL;
struct ListNode *tmp = NULL;
int carry = 0;
i... | thealgorithms-c/leetcode/src/2.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.146 | false | false | 1,014 | -1 |
#include <math.h>
#include <stdio.h>
float lerp(float k0, float k1, float t) { return k0 + t * (k1 - k0); }
float lerp_precise(int k0, int k1, float t) { return (1 - t) * k0 + t * k1; }
int main()
{
float start = 0;
float finish = 5;
float steps = 0;
printf("Input a number, this is the bigger bound ... | thealgorithms-c/math/lerp.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.095 | false | false | 624 | -1 |
// for strlen()
#include <string.h>
int numJewelsInStones(char *j, char *s)
{
// as strlen is O(n), store it once rather than using it in for loop
int cnt[500], lens = strlen(s), lenj = strlen(j), sol = 0;
memset(cnt, 0, sizeof(cnt));
// lookup to know which character occurs in j
for (int i = 0; i... | thealgorithms-c/leetcode/src/771.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.385 | false | false | 453 | -1 |
/* Includes structure for a node and a newNode() function which
can be used to create a new node in the tree.
It is assumed that the data in nodes will be an integer, though
function can be modified according to the data type, easily.
*/
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node *... | thealgorithms-c/data_structures/binary_trees/create_node.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/binary_trees | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.2 | false | false | 807 | -1 |
#define max(a,b) (((a)>(b))?(a):(b))
long getSum(int* nums, int numsSize, int divizor){
long result = 0;
for (int i = 0; i < numsSize; i++){
int value = nums[i] / divizor;
if (value * divizor != nums[i]){
value++;
}
result += value;
}
return result;
}
// D... | thealgorithms-c/leetcode/src/1283.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.108 | false | false | 1,010 | -1 |
/**
* @file
* @author [serturx](https://github.com/serturx/)
* @brief Encode a null terminated string using [Run-length encoding](https://en.wikipedia.org/wiki/Run-length_encoding)
* @details
* Run-length encoding is a lossless compression algorithm.
* It works by counting the consecutive occurences symbols
* an... | thealgorithms-c/misc/run_length_encoding.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.481 | false | false | 2,788 | -1 |
/**
* @file
* @brief Implementation of [Doubly linked list](https://en.wikipedia.org/wiki/Doubly_linked_list)
* @details
* A doubly linked list is a data structure with a sequence
* of components called nodes. Within that nodes there are
* three elements: a value recorded, a pointer to the next
* node, and a poi... | thealgorithms-c/data_structures/linked_list/doubly_linked_list.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.408 | false | false | 7,373 | -1 |
/* 1st way: Using 2 pointers */
int *sortedSquares(int *A, int ASize, int *returnSize)
{
int i, start = 0, end = ASize - 1;
int *res = malloc(ASize * sizeof(int));
*returnSize = ASize;
for (i = ASize - 1; i >= 0; i--)
{
if (abs(A[start]) > A[end])
{
res[i] = A[start] * A[... | thealgorithms-c/leetcode/src/977.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.129 | false | false | 823 | -1 |
/*
Prompt:
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
- '.' Matches any single character.
- '*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Constraints:
1 <= s.length <= 20
1 <=... | thealgorithms-c/leetcode/src/10.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.106 | false | false | 1,473 | -1 |
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* getRow(int rowIndex, int* returnSize){
int colIndex = rowIndex + 1;
int* ans = (int*) malloc(sizeof(int) * colIndex);
for (int i = 0; i < colIndex; i++)
{
ans[i] = 1;
}
*returnSize = colIndex;
... | thealgorithms-c/leetcode/src/119.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.2 | false | false | 492 | -1 |
/**
* @file
* @author [NVombat](https://github.com/NVombat)
* @brief Client-side implementation of [TCP Full Duplex
* Communication](http://www.tcpipguide.com/free/t_SimplexFullDuplexandHalfDuplexOperation.htm)
* @see tcp_full_duplex_server.c
*
* @details
* The algorithm is based on the simple TCP client and se... | thealgorithms-c/client_server/tcp_full_duplex_client.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.695 | false | false | 6,968 | -1 |
#include <stdio.h>
#include <stdlib.h>
#define len 5
int binarySearch(int array[], int leng, int searchX)
{
int pos = -1, right, left, i = 0;
left = 0;
right = leng - 1;
while (left <= right)
{
pos = left + (right - left) / 2;
if (array[pos] == searchX)
{
retur... | thealgorithms-c/searching/other_binary_search.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.077 | false | false | 867 | -1 |
/**
* @addtogroup hash Hash algorithms
* @{
* @file hash_adler32.c
* @author [Christian Bender](https://github.com/christianbender)
* @brief 32-bit [Adler hash](https://en.wikipedia.org/wiki/Adler-32) algorithm
*/
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
/**
* @brief 32-bit Adler algorithm i... | thealgorithms-c/hash/hash_adler32.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.449 | false | false | 1,093 | -1 |
/**
* \file
* \brief [Kohonen self organizing
* map](https://en.wikipedia.org/wiki/Self-organizing_map) (data tracing)
*
* \details
* This example implements a powerful self organizing map algorithm.
* The algorithm creates a connected network of weights that closely
* follows the given data points. This create... | thealgorithms-c/machine_learning/kohonen_som_trace.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.49 | false | false | 17,028 | -1 |
/**
* @{
* @file
* @brief Program to perform the [extended Euclidean
* algorithm](https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm)
*
* @details The extended Euclidean algorithm, on top of finding the GCD (greatest common
* divisor) of two integers a and b, also finds the values x and y such that
* ax... | thealgorithms-c/math/euclidean_algorithm_extended.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.519 | false | false | 3,900 | -1 |
/**
* Time complexity: O(log n).
* Space complexity: O(1).
* @details The array has a pattern that consists in of the existing sub-array to
* the left of the non-repeating number will satisfy the condition that
* each pair of repeated elements have their first occurrence at the even index
* ... | thealgorithms-c/leetcode/src/540.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.387 | false | false | 1,218 | -1 |
#include <limits.h>
int reverse(int x)
{
int rev = 0;
while (x != 0)
{
int pop = x % 10;
x /= 10;
if (rev > INT_MAX / 10 || (rev == INT_MAX / 10 && pop > 7))
return 0;
if (rev < INT_MIN / 10 || (rev == INT_MIN / 10 && pop < -8))
return 0;
rev ... | thealgorithms-c/leetcode/src/7.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.062 | false | false | 362 | -1 |
/**
* @file
* @brief [Shunting Yard Algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm)
* @details From Wikipedia: In computer science,
* the shunting yard algorithm is a method for parsing arithmetical or logical expressions, or a combination of both, specified in infix notation.
* It can produce ei... | thealgorithms-c/misc/shunting_yard.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.321 | false | false | 8,209 | -1 |
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Structure for storing edge
struct Edge
{
int src, dst, weight;
};
// Structure for storing a graph
struct Graph
{
int vertexNum;
int edgeNum;
struct Edge *edges;
};
// Constructs a graph with V vertices and E edges
void... | thealgorithms-c/data_structures/graphs/bellman_ford.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.154 | false | false | 3,338 | -1 |
bool isVowel(char chr){
switch(chr){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return true;
}
return false;
}
// Counting
// Runtime: O(n)
// Space: O(1... | thealgorithms-c/leetcode/src/1704.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.091 | false | false | 676 | -1 |
bool isPalindrome(int x)
{
if (x < 0 || (x % 10 == 0 && x != 0))
{
return false;
}
int revertedNumber = 0;
while (x > revertedNumber)
{
revertedNumber = revertedNumber * 10 + x % 10;
x /= 10;
}
return x == revertedNumber || x == revertedNumber / 10;
}
| thealgorithms-c/leetcode/src/9.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 310 | -1 |
#include <stdio.h>
#include <stdlib.h>
#include "hash_set.h"
extern hash_set_t *init_hash_set()
{
hash_set_t *set = (hash_set_t *)malloc(sizeof(hash_set_t));
set->keys = calloc(DEFAULT_HASH_SET_CAPACITY, sizeof(void **));
set->values = calloc(DEFAULT_HASH_SET_CAPACITY, sizeof(void **));
set->length = ... | thealgorithms-c/data_structures/hash_set/hash_set.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/hash_set | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.063 | false | false | 2,278 | -1 |
/**
* @file
* @author [Nairit11](https://github.com/Nairit11)
* @author [Krishna Vedala](https://github.com/kvedala)
* @brief Server side implementation of Server-Client system.
* @see client_server/client.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #ifdef HAS_UNISTD
// #include <unistd.h>... | thealgorithms-c/client_server/server.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.4 | false | false | 3,967 | -1 |
// C program for Kruskal's algorithm to find Minimum Spanning Tree
// of a given connected, undirected and weighted graph
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// a structure to represent a weighted edge in graph
struct Edge
{
int src, dest, weight;
};
// a structure to represent a connected,... | thealgorithms-c/data_structures/graphs/kruskal.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.316 | false | false | 4,995 | -1 |
#include <stdlib.h> // for qsort()
int cmp(const void* a, const void* b) {
const int *A = a, *B = b;
return (*A > *B) - (*A < *B);
}
int threeSumClosest(int* nums, int nums_size, int target) {
int i, j, k, result, sum3;
qsort(nums, nums_size, sizeof(int), cmp);
result = nums[0] + nums[1] + nums[2]... | thealgorithms-c/leetcode/src/16.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.036 | false | false | 804 | -1 |
/**
* @file
* @brief Conversion of [roman numerals](https://en.wikipedia.org/wiki/Roman_numerals) to decimal
* @details Roman numerals are an ancient Roman numeral system consisting of the symbols I, V, X, L, C, D, and M
*
* @author [Focusucof](https://github.com/Focusucof)
*/
#include <assert.h> /// for assert... | thealgorithms-c/conversions/roman_numerals_to_decimal.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.29 | false | false | 3,093 | -1 |
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *reverseList(struct ListNode *head)
{
struct ListNode *res = NULL;
while (head)
{
struct ListNode *pre_node = head;
head = head->next;
pre_node->nex... | thealgorithms-c/leetcode/src/206.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.368 | false | false | 377 | -1 |
struct TreeNode *insertIntoBST(struct TreeNode *root, int val)
{
if (root == NULL)
{
struct TreeNode *new_val = malloc(sizeof(struct TreeNode));
new_val->val = val;
new_val->left = new_val->right = NULL;
return new_val;
}
else
{
if (root->val >= val)
... | thealgorithms-c/leetcode/src/701.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 465 | -1 |
/**
* \file
* \brief [Problem 19](https://projecteuler.net/problem=19) solution
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
/**
* Function to get the number of days in a month.
* \param month month identified by an integer -\n
* > 0 = Jan and 11 = December
* \returns number of ... | thealgorithms-c/project_euler/problem_19/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_19 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.364 | false | false | 3,436 | -1 |
#define max(x,y)(((x)>(y))?(x):(y))
#define min(x,y)(((x)<(y))?(x):(y))
// Max stack. Runtime: O(n), Space: O(n)
// Algorithm description:
// - Calculate the stack of maximums from right board.
// - For each index find left maximum and right maximum of height
// - The each index if heights could place nor greater tha... | thealgorithms-c/leetcode/src/42.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.348 | false | false | 930 | -1 |
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN INT_MAX
int main(int argc, char **argv)
{
int *a, n = 10, i, j, temp, sum = 0;
float mean;
if (argc == 2)
{
n = atoi(argv[1]);
if (n >= MAX_LEN)
{
fprintf(stderr, "Maximum ... | thealgorithms-c/numerical_methods/mean.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.152 | false | false | 742 | -1 |
/**
* @file
* @brief Program to generate [Cantor ternary
* set](https://en.wikipedia.org/wiki/Cantor_set)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/** structure to define Cantor set */
typedef struct _cantor_set
{
double start; /**< start of interval */
double end; ... | thealgorithms-c/math/cantor_set.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.294 | false | false | 2,952 | -1 |
#include <stdio.h>
void stoogesort(int[], int, int);
int main()
{
int arr[100], i, n;
printf("How many elements do you want to sort: ");
scanf("%d", &n);
for (i = 0; i < n; i++) scanf(" %d", &arr[i]);
stoogesort(arr, 0, n - 1);
printf("Sorted array : \n");
for (i = 0; i < n; i++)
{
... | thealgorithms-c/sorting/stooge_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.03 | false | false | 722 | -1 |
#include <stdio.h>
#include <string.h>
/* Kabin-Karp algorithm for pattern searching
d: radix-d notation. Ex. number from 0->9, d = 10
q: prime number for hashing */
void rabin_karp_search(char *str, char *pattern, int d, int q)
{
int len_str = strlen(str);
int len_pat = strlen(pattern);
int i, h = 1... | thealgorithms-c/searching/pattern_search/rabin_karp_search.c | algorithms | thealgorithms-c | thealgorithms-c/searching/pattern_search | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.136 | false | false | 2,086 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxval(int a, int b)
{
if (a > b)
return a;
else
return b;
}
int maxDepth(struct TreeNode *root)
{
if (root == NULL)
return 0;
... | thealgorithms-c/leetcode/src/104.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.364 | false | false | 401 | -1 |
#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void shakersort(int *a, int n)
{
int p, i;
for (p = 1; p <= n / 2; p++)
{
for (i = p - 1; i < n - p; i++)
if (a[i] > a[i + 1])
{
swap... | thealgorithms-c/sorting/shaker_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.105 | false | false | 764 | -1 |
/**
* @file
* @brief Convert hexadecimal number to octal number (with decimal intermediary)
* @details
* The input is valid from 0 to 0xFFFF_FFFF_FFFF_FFFF.
*
* At first, this program converts a hex string to an unsigned long long
* decimal, and then to an octal string.
*
* When there is an invalid character i... | thealgorithms-c/conversions/hexadecimal_to_octal2.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.314 | false | false | 2,592 | -1 |
/**
* \file
* \brief [Problem 9](https://projecteuler.net/problem=9) solution - A naive
* implementation
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdio.h>
/** Main function */
int main(void)
{
for (int a = 1; a < 300; a++)
for (int b = a + 1; b < 400; b++)
for (i... | thealgorithms-c/project_euler/problem_9/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_9 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.333 | false | false | 675 | -1 |
/**
* @file
* \brief Find approximate solution for \f$f(x) = 0\f$ using
* Newton-Raphson interpolation algorithm.
*
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <complex.h> /* requires minimum of C99 */
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <t... | thealgorithms-c/numerical_methods/newton_raphson_root.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.492 | false | false | 1,859 | -1 |
/*Includes structure for a node which can be use to make new nodes of the Linked
List. It is assumed that the data in nodes will be an integer, though function
can be modified according to the data type, easily. deleteNode deletes a node
when passed with a key of the node.
*/
#include <stdio.h>
#include <stdlib.h... | thealgorithms-c/data_structures/linked_list/singly_link_list_deletion.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.063 | false | false | 4,265 | -1 |
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
int main()
{
Stack_T stk;
stk = Stack_init();
Stack_push(stk, (int *)1);
Stack_push(stk, (int *)2);
Stack_push(stk, (int *)3);
Stack_push(stk, (int *)4);
printf("Size: %d\n", Stack_size(stk));
Stack_print(stk)... | thealgorithms-c/data_structures/stack/stack_linked_list/main.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/stack | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.182 | false | false | 500 | -1 |
/* Ascending priority queue using Linked List - Program to implement Ascending
* priority queue using Linked List */
/*A priority queue is a special type of queue in which each element is
associated with a priority and is served according to its priority. If elements
with the same priority occur, they are served acco... | thealgorithms-c/data_structures/linked_list/ascending_priority_queue.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/linked_list | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.061 | false | false | 5,146 | -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().
*/
int** generate(int numRows, int* returnSize, int** returnColumnSizes){
*returnSize = numRow... | thealgorithms-c/leetcode/src/118.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.304 | false | false | 805 | -1 |
/**
* @file
* @brief [ROT13](https://en.wikipedia.org/wiki/ROT13) is a simple letter
* substitution cipher that replaces a letter with the 13th letter after it in
* the alphabet.
* @details ROT13 transforms a piece of text by examining its alphabetic
* characters and replacing each one with the letter 13 places... | thealgorithms-c/cipher/rot13.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.528 | false | false | 1,905 | -1 |
/**
* @file
* @brief Sorting of array list using [bead
* sort](https://en.wikipedia.org/wiki/Bead_sort)
*/
#include <stdio.h>
#include <stdlib.h>
/**
* @addtogroup sorting Sorting algorithms
* @{
*/
/** Create easy access of elements from a 2D matrix stored in memory as a 1D
* array
*/
#define BEAD(i, j) bead... | thealgorithms-c/sorting/bead_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.345 | false | false | 2,008 | -1 |
int romanToInt(char *s)
{
int romanToInt = 0;
for (int i = 0; i < strlen(s); i++)
{
switch (s[i])
{
case 'I':
if (i + 1 < strlen(s))
{
if (s[i + 1] == 'V' || s[i + 1] == 'X')
{
romanToInt -= 1;
... | thealgorithms-c/leetcode/src/13.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 1,335 | -1 |
bool detectCapitalUse(char *word)
{
int len = strlen(word);
if (len == 1)
return 1;
int countUpper = 0, i;
for (i = 0; i < len; i++)
{
if (isupper(word[i]))
countUpper++;
}
/* All lower case */
if (countUpper == 0)
return 1;
/* 1st character is upp... | thealgorithms-c/leetcode/src/520.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.095 | false | false | 897 | -1 |
double findMedianSortedArrays(int *nums1, int nums1Size, int *nums2,
int nums2Size)
{
int index1 = 0;
int index2 = 0;
int v[nums1Size + nums2Size];
int v_index = 0;
while (index1 < nums1Size && index2 < nums2Size)
{
if (nums1[index1] <= nums2[index2])
... | thealgorithms-c/leetcode/src/4.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 1,032 | -1 |
/* Sorting of array list using binary insertion sort
* Using binary search to find the proper location for
* inserting the selected item at each iteration. */
#include <stdio.h>
#include <stdlib.h>
/*Displays the array, passed to this method*/
void display(int *arr, int n)
{
int i;
for (i = 0; i < n; i++)
... | thealgorithms-c/sorting/binary_insertion_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.169 | false | false | 1,844 | -1 |
int search(int *nums, int numsSize, int target)
{
int low = 0, high = numsSize - 1;
while (low <= high)
{
int mid = low + (high - low) / 2;
if (target > nums[mid])
{
low = mid + 1;
}
else if (target < nums[mid])
{
high = mid - 1;
... | thealgorithms-c/leetcode/src/704.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.032 | false | false | 713 | -1 |
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Structure for storing a graph
struct Graph
{
int vertexNum;
int **edges;
};
// Constructs a graph with V vertices and E edges
void createGraph(struct Graph *G, int V)
{
G->vertexNum = V;
G->edges = (int **)malloc(V * siz... | thealgorithms-c/data_structures/graphs/floyd_warshall.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.202 | false | false | 2,822 | -1 |
// Dynamic programming can be applied here, because every solved sub-problem has
// an optimal sub-solution
// Searching backwards from end to start, we can incrementally calculate number
// of paths to destination. i.e. start from bottom-right, and calculate
// leftwards (lowest row should all be 1). then go to second... | thealgorithms-c/leetcode/src/62.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.412 | false | false | 1,195 | -1 |
// Queue ADT implementation ... COMP2521
#include "queue.h"
#include <assert.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
} NodeT;
typedef struct QueueRep
{
int length;
NodeT *head;
NodeT *tail;
} QueueRep;
// set up empty queue
queue newQueue()
{
queue Q = mallo... | thealgorithms-c/data_structures/graphs/queue.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.33 | false | false | 2,764 | -1 |
#include <stdbool.h>
#include <stdio.h>
#include "Graph.h"
#include "queue.h"
#define MAX_NODES 1000
int visited[MAX_NODES]; // array to store visiting order
// indexed by vertex 0..nV-1
bool findPathBFS(Graph g, int nV, Vertex src, Vertex dest)
{
Vertex v;
for (v = 0; v < nV; v++) ... | thealgorithms-c/data_structures/graphs/bfs_queue.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.243 | false | false | 3,274 | -1 |
// Fucntion to calculate min of values a and b
int min(int a, int b) { return ((a < b) ? a : b); }
// Two pointer approach to find maximum container area
int maxArea(int *height, int heightSize)
{
// Start with maximum container width
int start = 0;
int end = heightSize - 1;
int res = 0;
while (st... | thealgorithms-c/leetcode/src/11.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.182 | false | false | 671 | -1 |
/**
@file
@author [Krishna Vedala](https://github.com/kvedala)
@date 2 October, 2019
@brief Compute \f$m^{mth}\f$ Fibonacci number using the formulae:
\f{eqnarray*}{
F_{2n-1} &=& F_n^2 + F_{n-1}^2 \\
F_{2n} &=& F_n\left(2F_{n-1} + F_n\right)
\f}
*/
#include <locale.h>
#include ... | thealgorithms-c/math/fibonacci_fast.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.333 | false | false | 1,881 | -1 |
/**
* \file
* \brief [Problem 401](https://projecteuler.net/problem=401) solution -
* Sum of squares of divisors
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#ifdef _OPENMP
#... | thealgorithms-c/project_euler/problem_401/sol1.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_401 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.348 | false | false | 3,316 | -1 |
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA
*
* 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 licensed under th... | thealgorithms-c/client_server/bool.h | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.87 | false | false | 1,224 | -1 |
/*
* C Program to Convert Binary to Hexadecimal
*/
#include <stdio.h>
int main()
{
long int binary, hexa = 0, i = 1, remainder;
printf("Enter the binary number: ");
scanf("%ld", &binary);
while (binary != 0)
{
remainder = binary % 10;
hexa = hexa + remainder * i;
i = i * ... | thealgorithms-c/conversions/binary_to_hexadecimal.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.211 | false | false | 434 | -1 |
#include "dict.h"
#include <stdio.h>
#include <stdlib.h>
/* simple constructor */
Dictionary *create_dict(void)
{
Dictionary *p_dic = malloc(sizeof(Dictionary));
if (p_dic)
{
p_dic->number_of_elements = 0;
/* initializes the elemens of the array with NULL-pointer */
for (int i = 0;... | thealgorithms-c/data_structures/dictionary/dict.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/dictionary | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.167 | false | false | 2,055 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool checkSymmetric(struct TreeNode *left, struct TreeNode *right)
{
if (!left || !right)
return left == right;
if (left->val != right->val)
retu... | thealgorithms-c/leetcode/src/101.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.381 | false | false | 549 | -1 |
int myAtoi(char *str)
{
int minusFlag = 0;
int length = strlen(str);
long int result = 0;
char numberBuffer[11];
int counter = 0;
while (str[counter] == ' ')
{
counter++;
}
str = &str[counter];
counter = 0;
for (int i = 0; i < length; i++)
{
if (i == 0)
... | thealgorithms-c/leetcode/src/8.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 1,484 | -1 |
bool isUnivalTree(struct TreeNode *root)
{
if (root == NULL)
return 1;
if (root->left)
{
if (root->left->val != root->val)
return 0;
}
if (root->right)
{
if (root->right->val != root->val)
return 0;
}
return isUnivalTree(root->left) && isUn... | thealgorithms-c/leetcode/src/965.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0 | false | false | 345 | -1 |
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
int maximizeTarget(char * answerKey, char targetChar, int k){
int leftIndex = -1;
int result = 0;
int currTargetChars = 0;
int lenAnswerKey = strlen(answerKey);
for (int rightIndex = 0; rightIndex < lenAnswerKey; rightIndex++){
char ch = answerKey[... | thealgorithms-c/leetcode/src/2024.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.148 | false | false | 929 | -1 |
/**
* @file
* @brief Functions related to 3D vector operations.
* @author Krishna Vedala
*/
#include <stdio.h>
#ifdef __arm__ // if compiling for ARM-Cortex processors
#define LIBQUAT_ARM
#include <arm_math.h>
#else
#include <math.h>
#endif
#include <assert.h>
#include "geometry_datatypes.h"
/**
* @addtogroup ... | thealgorithms-c/geometry/vectors_3d.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.547 | false | false | 6,481 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* bstFromPreorder(int* preorder, int preorderSize)
{
struct TreeNode* new;
int left_ptr;
new = malloc(sizeof(struct TreeNode));
new->val ... | thealgorithms-c/leetcode/src/1008.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.235 | false | false | 870 | -1 |
int coundDevices(char* bankRow){
int result = 0;
int bankRowSize = strlen(bankRow);
for(int i = 0; i < bankRowSize; i++){
if (bankRow[i] == '1'){
result++;
}
}
return result;
}
// Counting devices in each row
// Runtime: O(n*m), n-number of bank rows, m - max size of ro... | thealgorithms-c/leetcode/src/2125.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.115 | false | false | 683 | -1 |
int findMin(int *nums, int numsSize)
{
int low = 0, high = numsSize - 1;
while (low < high)
{
int mid = low + (high - low) / 2;
/* minimum is on left side */
if (nums[mid] < nums[high])
high = mid;
/* minimum is on right side */
else
low = mid ... | thealgorithms-c/leetcode/src/153.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.133 | false | false | 355 | -1 |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode *convertBST(int *nums, int left, int right)
{
if (left > right)
return NULL;
else
{
int mid = (right + left) / 2;
str... | thealgorithms-c/leetcode/src/108.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.276 | false | false | 726 | -1 |
/**
* @addtogroup hash Hash algorithms
* @{
* @file
* @author [Daniel Murrow](https://github.com/dsmurrow)
* @brief [Blake2b cryptographic hash
* function](https://www.rfc-editor.org/rfc/rfc7693)
*
* The Blake2b cryptographic hash function provides
* hashes for data that are secure enough to be used in
* cryp... | thealgorithms-c/hash/hash_blake2b.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.419 | false | false | 16,001 | -1 |
/**
* @file
* @brief Convert decimal to binary using recursion algorithm
*/
#include <assert.h>
/**
* Decimal to binary using recursion algorithm.
* For example, if number = 5, the function returns the decimal integer 101.
* @param number positive integer number to convert
* @returns integer with digits represe... | thealgorithms-c/conversions/decimal_to_binary_recursion.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.441 | false | false | 892 | -1 |
/**
* \file
* \brief Compute statistics for data entered in rreal-time
* \author [Krishna Vedala](https://github.com/kvedala)
*
* This algorithm is really beneficial to compute statistics on data read in
* realtime. For example, devices reading biometrics data. The algorithm is
* simple enough to be easily imple... | thealgorithms-c/numerical_methods/realtime_stats.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.41 | false | false | 5,136 | -1 |
/*
author: Christian Bender
This header represents the public stack-interface.
The stack is generic and self growing.
*/
#ifndef __STACK__
#define __STACK__
/*
initStack: initializes the stack with a capacity of 10 elements.
*/
void initStack();
/*
push: pushs the argument onto the stack
*/
void... | thealgorithms-c/data_structures/stack/stack.h | algorithms | thealgorithms-c | thealgorithms-c/data_structures/stack | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.515 | false | false | 695 | -1 |
// Graph ADT interface ... COMP2521
#include <stdbool.h>
typedef struct GraphRep *Graph;
// vertices are ints
typedef int Vertex;
// edges are pairs of vertices (end-points)
typedef struct Edge
{
Vertex v;
Vertex w;
} Edge;
Graph newGraph(int);
void insertEdge(Graph, Edge);
void removeEdge(Graph, Edge);
boo... | thealgorithms-c/data_structures/graphs/graph.h | algorithms | thealgorithms-c | thealgorithms-c/data_structures/graphs | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.667 | false | false | 1,833 | -1 |
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
// Dynamic programming approach. Down -> Up.
// Runtime: O(n)
// Space: O(1)
int minimumDeletions(char * s){
int len = strlen(s);
int aStateValue = s[0] == 'b';
int bStateValue = 0;
int newAStateValue;
int newBStateValue;
for(int i = 1; i <... | thealgorithms-c/leetcode/src/1653.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.19 | false | false | 696 | -1 |
const charLength = 26;
int* charsCount(char* word){
int* result = calloc(charLength, sizeof(int));
int wordLen = strlen(word);
for (int i = 0; i < wordLen; i++){
result[word[i] - 'a']++;
}
return result;
}
int diff(const int *i, const int *j)
{
return *i - *j;
}
// Counting
// Runtim... | thealgorithms-c/leetcode/src/1657.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.143 | false | false | 1,373 | -1 |
int searchInsert(int *nums, int numsSize, int target)
{
int low = 0, high = numsSize - 1, mid;
while (low <= high)
{
mid = low + (high - low) / 2;
if (target > nums[mid])
low = mid + 1;
else if (target < nums[mid])
high = mid - 1;
else
retu... | thealgorithms-c/leetcode/src/35.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.034 | false | false | 649 | -1 |
/* demo.c -- Implementations of multikey quicksort and ternary search trees
Usage
demo Run basic timings on /usr/dict/words
demo <file> Run basic timings on <file>
demo <file> trysearch Interactive pm and nn search on <file>
demo <file> nncost Run near neigbhor expers on... | thealgorithms-c/sorting/multikey_quick_sort.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.082 | false | false | 8,310 | -1 |
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
float x[20], y[20], a, sum, p;
int n, i, j;
printf("Enter the no of entry to insert->");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("enter the value of x%d->", i);
scanf("%f", &x[i]);
printf("... | thealgorithms-c/numerical_methods/lagrange_theorem.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.073 | false | false | 954 | -1 |
/**
* @file
* @author [NVombat](https://github.com/NVombat)
* @brief Server-side implementation of [TCP Full Duplex
* Communication](http://www.tcpipguide.com/free/t_SimplexFullDuplexandHalfDuplexOperation.htm)
* @see tcp_full_duplex_client.c
*
* @details
* The algorithm is based on the simple TCP client and se... | thealgorithms-c/client_server/tcp_full_duplex_server.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.695 | false | false | 7,834 | -1 |
/**
* @file
* @brief Program to identify if a number is [prime
* number](https://en.wikipedia.org/wiki/Prime_number) or not
*/
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
/**
* Check if a given number is prime number or not
* @param x number to check
* @return `true` if given n... | thealgorithms-c/math/prime.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.369 | false | false | 1,388 | -1 |
uint32_t reverseBits(uint32_t n)
{
uint TotalBits = 32;
uint32_t reverse_int = 0; // stored in memory as 32 bits, each bit valued 0
uint i;
for (i = 0; i < TotalBits; i++)
{
if ((n & (UINT32_C(1)
<< i))) // if the bit on the ith position of 32 bit input is
... | thealgorithms-c/leetcode/src/190.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.346 | false | false | 1,169 | -1 |
/**
* \file
* \brief [Problem 4](https://projecteuler.net/problem=4) solution
*/
#include <stdio.h>
/** Check if number is palindromic
* \param[in] n number to check
* \returns 1 if palindromic
* \returns 0 if not palindromic
*/
int is_palindromic(unsigned int n)
{
unsigned int reversed = 0, t = n;
whi... | thealgorithms-c/project_euler/problem_4/sol.c | algorithms | thealgorithms-c | thealgorithms-c/project_euler/problem_4 | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.289 | false | false | 782 | -1 |
/*
AUTHOR: Christian Bender
DATE: 12.02.2019
DESCRIPTION: This program calculates the prime factoriziation of a positive
integer > 1
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* initial length of the dynamic array */
#define LEN 10
/* increasing range */
#define... | thealgorithms-c/math/prime_factoriziation.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.132 | false | false | 3,151 | -1 |
#include "word_count.h"
#include <string.h>
/*
word_count: returns the full number of words in the input_text,
otherwise an error code: (see below)
error codes: EXCESSIVE_LENGTH_WORD -1
EXCESSIVE_NUMBER_OF_WORDS -2
The function manipulates the given structure of type ... | thealgorithms-c/exercism/word_count/word_count.c | algorithms | thealgorithms-c | thealgorithms-c/exercism/word_count | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.2 | false | false | 2,343 | -1 |
/*
author: Christian Bender
This is a simple test program for the dictionary.
*/
#include <stdio.h>
/* includes the dictionary */
#include "dict.h"
int main(void)
{
Dictionary *testObj1;
Dictionary *testObj2;
int value = 28;
testObj1 = create_dict();
testObj2 = create_dict();
add_i... | thealgorithms-c/data_structures/dictionary/test_program.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/dictionary | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.324 | false | false | 1,094 | -1 |
/*------------------Trie Data Structure----------------------------------*/
/*-------------Implimented for search a word in dictionary---------------*/
/*-----character - 97 used for get the character from the ASCII value-----*/
// needed for strnlen
#define _POSIX_C_SOURCE 200809L
#include <stdbool.h>
#include <std... | thealgorithms-c/data_structures/trie/trie.c | algorithms | thealgorithms-c | thealgorithms-c/data_structures/trie | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.331 | false | false | 5,241 | -1 |
// Dynamic Programming
// Runtime: O(n)
// Space: O(1)
int tribonacci(int n){
int t0 = 0;
int t1 = 1;
int t2 = 1;
if (n == 0) {
return t0;
}
if (n == 1){
return t1;
}
if (n == 2){
return t2;
}
for (int i = 0; i < n - 2; i++){
int nextT = t0 + t... | thealgorithms-c/leetcode/src/1137.c | algorithms | thealgorithms-c | thealgorithms-c/leetcode/src | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.125 | false | false | 406 | -1 |
#include <stdio.h>
int main()
{
int a[16500], T;
long long int i, j;
printf("Enter number of test cases : ");
scanf("%d", &T);
while (T--)
{
for (i = 0; i < 16500; i++)
{
a[i] = 0;
}
a[1] = 1;
int N, carry = 0, count = 0;
printf("En... | thealgorithms-c/math/large_factorials.c | algorithms | thealgorithms-c | thealgorithms-c | GPL-3.0 | GPL-3.0 | e5dad3fa8def3726ec850ca66a7f51521f8ad393 | c | false | 0.024 | false | false | 892 | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.