Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- dart:io
- flutter button
- flutter tcpip client
- flutter
- debug banner
- TCPIP
- debugShowCheckedModeBanner
- ubuntu 19 한글 입력
- ListView.build
- Server
- Properties.Settings.Default
- flutter tcpip server
- Listview filtering
- c
- AlertDialog
- array
- peaks
- showDialog
Archives
- Today
- Total
Louie De Janeiru
Find peaks from array in C 본문
#include <stdio.h>
int getPeaksFromArray(int* nums, int len, int *peaks)
{
int pi = 0;
for (int i = 0; i < len; i++)
{
if ( (i == 0 && nums[i + 1] < nums[i]) || /* first element */
((i == len) && nums[i - 1] < nums[i]) || /* last element */
(nums[i] > nums[i - 1] && nums[i] > nums[i + 1]) /* elements in the middle */
)
{
peaks[pi++] = nums[i];
}
}
return pi;
}
int main()
{
int arr[] = { 1, 3, 20, 4, 9, 10, 16, 70, 20, 4, 1, 9, 6, 3, 80, 89, 98, 88, 60, 85, 74, 80, 2, 5, 3, 9, 6, 7, 8, 9, 12, 3, 8 };
int peaks[sizeof(arr) / sizeof(arr[0])];
int pi = 0;
pi = getPeaksFromArray(arr, sizeof(arr) / sizeof(int), peaks);
for (int i = 0; i < pi; i++)
printf("%d\n", peaks[i]);
return 0;
}
'Utils' 카테고리의 다른 글
git_hub simple 'how to' (0) | 2020.11.20 |
---|---|
JAVA HOME (0) | 2020.05.16 |
Terminal option flag (0) | 2020.02.27 |
Elevation, Azimuth (0) | 2019.07.04 |
Win ISO down (0) | 2019.06.06 |