#include <stdio.h>
double get_next(double *);
double get_before(double *);
int i;
int main()
{
double ary[]={0.1, 0.3, 0.5, 0.7, 0.9};
printf("next호출 : %.1lf\n", get_next(ary));
printf("next호출 : %.1lf\n", get_next(ary));
printf("before호출 : %.1lf\n", get_before(ary));
printf("before호출 : %.1lf\n", get_before(ary));
return 0;
}
double get_next(double *ap)
{
double temp;
temp=ap[i];
i++;
return temp;
}
double get_before(double *ap)
{
double temp;
temp=ap[i];
i--;
return temp;
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
여기에서 next를 호출 한 다음 before를 호출 하였는데요 둘의 위치를 바꾼다면 어떻게 수정해야 되죠?
0.1 이전을 호출하면 맨처음으로 돌아가게 한다던가 이런식으로요.. 부탁드립니다.
// 원형큐 방식으로 하면 될거 같은데요.^^
#define MAX_COUNT 5 // 최대값을 설정하고,
double get_next(double *ap)
{
double temp;
temp=ap[i];
i++;
if(i>MAX_COUNT-1) i=0; //최대값보다 크면 0으로
return temp;
}
double get_before(double *ap)
temp=ap[i];{
double temp;
i--;
if(i<0) i=MAX_COUNT-1; //0보다 작으면 최대값으로
return temp;
}