FlexArray
FlexArray
is a Python library that provides an array-like structure with dynamic memory allocation features similar to C's malloc
, realloc
, and free
.
Installation
You can install the package via pip:
pip install flexarray
Usage
Implementing Array with flexarray
from flexarray.array import Array
arr = Array(3)
arr[0] = 10
arr[1] = 20
print(arr)
arr[5] = 50
print(arr)
arr.malloc(5)
print(arr)
arr.realloc(10)
print(arr)
arr.free()
print(arr)
Using Mathematics and Sorting on FlexArray
from flexarray.array import Array
from flexarray.mathematics import (
SumOfElements, AverageOfElements, MaxElement, MinElement,
ProductOfElements, MedianOfElements, ModeOfElements
)
from flexarray.sorting import BubbleSort, SelectionSort, InsertionSort
arr = Array(6)
arr[0] = 10
arr[1] = 20
arr[2] = 30
arr[3] = 40
arr[4] = 50
arr[5] = 60
print("Sum of elements:", SumOfElements(arr))
print("Average of elements:", AverageOfElements(arr))
print("Maximum element:", MaxElement(arr))
print("Minimum element:", MinElement(arr))
print("Product of elements:", ProductOfElements(arr))
print("Median of elements:", MedianOfElements(arr))
print("Mode of elements:", ModeOfElements(arr))
BubbleSort(arr)
print("Array after Bubble Sort:", arr)
arr.realloc(6)
arr[0], arr[1], arr[2], arr[3], arr[4], arr[5] = 50, 40, 30, 20, 10, 60
SelectionSort(arr)
print("Array after Selection Sort:", arr)
arr.realloc(6)
arr[0], arr[1], arr[2], arr[3], arr[4], arr[5] = 60, 50, 40, 30, 20, 10
InsertionSort(arr)
print("Array after Insertion Sort:", arr)