TagAlgorithms

All-around function to find mins/maxs, in order, distinct elements in array

It this post you can find a function in C which is a able to find X minimum or maximum elements in a given array, order the output either ascended or descended and get either distinct elements or duplications. Of course this function is far away from optimal solutions as it is better to use specific algorithms depending on your needs, however for fast experimentation it is useful. You can use...

Find masked pattern in 1D array – C source code

The following example finds the first occurrence of pattern in a given array and returns the address of that position. Moreover it takes into account a mask, which is helpful for inconsistent pattern formats like : 2,3,X,X,3,1 where X should be ignored. Below you will find the source code and a working sample.

A simple generic C Stack for static or dynamic memory usage

Following the  previous post about Queues, In this post i publish a simple modular stack written in C which can be used either by assigning a static space for the elements of a dynamic one (malloc etc). In computer science, a stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes...

A simple generic C Queue for static or dynamic memory usage

In this post i publish a simple modular queue written in C which can be used either by assigning a static space for the elements of a dynamic one (malloc etc). Queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order. The only requirement is that the memory space which will hold the queue items have to be allocated in prior. Below is...

The problem of “Beautiful Arrays” with C Source code

An array is called beautiful if for every pair of numbers , , (), there exists an  such that . Note that can be equal to or too. Input First line of the input contains an integer T denoting the number of test cases. T test cases follow. First line of each test case contains an integer n denoting number of elements in a. Next line contains n space separated integers denoting the array a. Output...

How to left-trim a C string

In various instances, there’s a need to eliminate leading white spaces from a C-string. The provided code snippet efficiently accomplishes this task using a straightforward approach. By employing this uncomplicated method, unnecessary white spaces at the beginning of the C-string are effectively stripped away. This simplistic solution proves useful in scenarios where a basic yet effective...

C-strings merging

This handy code snippet plays a crucial role in merging C strings seamlessly. By leveraging the built-in C-string function strcpy, it allows us to effortlessly combine various strings into a single one, all without the hassle of manually managing memory space. The simplicity of this approach ensures efficiency in string concatenation. I t’s worth noting that the implementation of this...

Memory Management Algorithms for MMU-Less Systems

There are several different approaches for memory management that can solve the fragmentation problem on MMU-less embedded systems. Each algorithm is classified according to the way that it finds a free block of the most appropriate size. There are five categories extendedly analyzed in M. Masmano el al. [1], Sun et al. [2] and P. R. Wilson [10] works: Sequential Fit, Segregated Free Lists...

Disclaimer: The present content may not be used for training artificial intelligence or machine learning algorithms. All other uses, including search, entertainment, and commercial use, are permitted.

Categories

Tags