Skip to content

Instantly share code, notes, and snippets.

@itrobotics
Created August 24, 2015 17:08
Show Gist options
  • Select an option

  • Save itrobotics/263cbe54969f717ff1db to your computer and use it in GitHub Desktop.

Select an option

Save itrobotics/263cbe54969f717ff1db to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
void find_peak(int *a,int size);
int main(void)
{
FILE *fp;
int i=0,v;
int data[MAX];
if ((fp = fopen("sample.txt", "r")) == NULL)
{
fprintf(stdout,"Can't open file.\n");
exit(1);
}
while (fscanf(fp,"%d",&v) == 1 && i<MAX)
{
data[i++]=v;
}
find_peak(data,i);
fclose(fp);
getchar();
return 0;
}
void find_peak(int *a,int size)
{
int i,j,k;
int n,m;
int top_peek[30];
int bottom_peek[30];
n=m=0;
for(i=0,j=1,k=2;k<size;i++,j++,k++) {
if (a[j]>a[i] && a[j]>a[k]) {
printf("top:%d\n",a[j]);
top_peek[n++]=j;
} else if (a[i]>a[j] && a[j]<a[k]) {
printf("bottom:%d\n",a[j]);
bottom_peek[m++]=j;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment