Skip to content

A C utility library providing a comprehensive toolkit for array manipulation and analysis. Includes routines for sorting (bubble_sort), searching (linear, first/last occurrence), in-place modification (rotation, reversal, remove_duplicates), and statistical analysis.

Notifications You must be signed in to change notification settings

DEMiHAT/utility_v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GODL!KE C Utility Library 🧰

A collection of general-purpose utility functions in C for common operations related to math, strings, and arrays.

How to Use

  1. Place utility.c and utility.h into your project's source directory.
  2. Include the header file in your code:
    #include "utility.h"
  3. When compiling, remember to include utility.c in the command:
    gcc your_main_file.c utility.c -o your_program

Function Reference

Here is a complete list of all available functions.

General Math & Logic

  • void swap(int *a, int *b): Swaps the values of two integers.
  • int max(int a, int b): Returns the maximum of two integers.
  • int min(int a, int b): Returns the minimum of two integers.
  • unsigned long long factorial(int n): Calculates the factorial of a number.
  • int is_prime(int n): Checks if a number is prime. Returns 1 if prime, 0 otherwise.

String Manipulation

  • int string_length(const char *str): Calculates the length of a string.
  • void reverse_string(char *str): Reverses a string in place.

Array Sorting & Searching

  • void bubble_sort(int arr[], int size): Sorts an array in ascending order.
  • int find_element(int arr[], int size, int target): Finds the first index of a target element. Returns -1 if not found.
  • int find_first_occurrence(int arr[], int size, int value): Finds the first index of a value. Returns -1 if not found.
  • int find_last_occurrence(int arr[], int size, int value): Finds the last index of a value. Returns -1 if not found.

Array Manipulation

  • void reverse_array(int arr[], int size): Reverses the elements of an array in place.
  • void copy_array(int src[], int dest[], int size): Copies elements from a source array to a destination array.
  • int remove_duplicates(int arr[], int size): Removes duplicate elements from a sorted array and returns the new size.
  • void fill_array(int arr[], int size, int value): Fills an array with a specific value.
  • void rotate_array_left(int arr[], int size, int k): Rotates an array to the left by k positions.
  • void rotate_array_right(int arr[], int size, int k): Rotates an array to the right by k positions.
  • void concatenate_arrays(int arr1[], int size1, int arr2[], int size2, int dest[]): Concatenates two arrays into a destination array.
  • void get_subarray(int arr[], int size, int start, int end, int dest[]): Creates a subarray from a start to an end index.
  • void zero_array(int arr[], int size): Sets all elements of an array to zero.
  • void merge_sorted_arrays(int arr1[], int size1, int arr2[], int size2, int dest[]): Merges two sorted arrays into a single sorted destination array.

Array Information & Properties

  • int array_sum(int arr[], int size): Calculates the sum of all elements in an array.
  • int array_max(int arr[], int size): Finds the maximum element in an array.
  • int array_min(int arr[], int size): Finds the minimum element in an array.
  • int is_sorted(int arr[], int size): Checks if an array is sorted in ascending order.
  • int arrays_equal(int arr1[], int arr2[], int size1, int size2): Checks if two arrays are identical.
  • double array_median(int arr[], int size): Calculates the median of a sorted array.
  • int count_occurrences(int arr[], int size, int value): Counts how many times a value appears in an array.
  • int array_contains(int arr[], int size, int value): Checks if an array contains a specific value.
  • int is_array_palindrome(int arr[], int size): Checks if an array is a palindrome. =======

utility-v1

C language Utility functions!

9ac2b44084f18597751ddd061b0f2b79c3139faa

About

A C utility library providing a comprehensive toolkit for array manipulation and analysis. Includes routines for sorting (bubble_sort), searching (linear, first/last occurrence), in-place modification (rotation, reversal, remove_duplicates), and statistical analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages