A algorithm library for C/C++ programmer
- v2.0.1
- developer 開發者: LAZPbanahaker
- latest update 最近更新日期: 2022/07/14
- support function 支援函式數量: 14
- 更新內容: Linked list support
- v1.0.1
- developer 開發者: LAZPbanahaker
- latest update 最近更新日期: 2021/12/20
- support function 支援函式數量: 12
- Linked list Support
Put al.h file in your project folder, then #include this header file
將 al.h 放在專案資料夾下然後用 #include 方式引入如下
#include "al.h"- println()
- arrayDisplay()
- MAX()
- MIN()
- maxInArray()
- minInArray()
- bubbleSort()
- insertSort()
- binarySearch()
- linearSearch()
- insertElement()
- deleteElement()
using those algorithm function you can programming faster
- auto include <stdio.h> and <stdlib.h>(in C)
- not include C++ basic library
Code
#include "al.h" // 引入函式庫 import library
int main() {
println("algorithm library test"); // 全行顯示 (自動加入'\n')
int arr[10] = {5, 4, 3, 8, 7, 6, 1, 9, 288, 2};
arrayDisplay(arr, 10, 0); // 顯示陣列 display array
insertSort(arr, 10); // 陣列排序 array sort
arrayDisplay(arr, 10, 0); // 顯示陣列 display array
int searchResult = binarySearch(arr, 10, 4); // 陣列搜尋 array search
printf("searchResult: %d\n", searchResult);
int maxValueInArray = maxInArray(arr, 10); // 陣列最大值 largest value in array
int minValueInArray = minInArray(arr, 10); // 陣列最小值 smallest value in array
printf("maxValueInArray: %d\n", maxValueInArray);
printf("minValueInArray: %d\n", minValueInArray);
double a = 10.6, b = 8.5;
double max = MAX(a, b), min = MIN(a, b); // 取大值與小值
printf("max: %f, min: %f\n", max, min);
insertElement(2, arr, 10, 13); // 在 arr 中的索引三插入13 insert 13 to index_2 in arr
arrayDisplay(arr, 10, 0);
deleteElment(3, arr, 10); // 刪除 arr 中的索引 3 delete index_3 in arr
arrayDisplay(arr, 10, 0);
return 0;
}Output
algorithm library test
[ 5, 4, 3, 8, 7, 6, 1, 9, 288, 2 ]
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 288 ]
searchResult: 3
maxValueInArray: 288
minValueInArray: 1
max: 10.600000, min: 8.500000
[ 1, 2, 13, 3, 4, 5, 6, 7, 8, 9 ]
[ 1, 2, 13, 4, 5, 6, 7, 8, 9, 0 ]