'진주의 배설물/알고리즘 소스'에 해당되는 글 3건
- 2012.02.03
- 2012.02.03
- 2012.02.03
[C언어] 배열과 함수만을 이용한 Queue (0) | 2012.02.03 |
---|---|
[C언어] 2차원 배열 - 달팽이 알고리즘 - (0) | 2012.02.03 |
#include <stdio.h>
int ary[5]={0,};
int rear=-1;
int front=-1;
void init_Queue();
void InQueue();
void DeQueue();
void Print_Queue();
void All_Clear();
int main(void)
{
int i;
init_Queue();
printf("Queue에 데이터를 입력합니다.\n");
//0~4까지 입력
for(i=0; i<4; i++)
{
InQueue();
}
Print_Queue();
printf("Queue에 데이터를 입력합니다.\n");
//5까지 입력, 오버플로우 확인
for(i=0; i<2; i++)
{
InQueue();
}
Print_Queue();
//0~4까지 삭제
printf("Queue에 데이터를 삭제합니다.\n");
for(i=0; i<4; i++)
{
DeQueue();
}
Print_Queue();
//5까지 삭제, 언더플로우 확인
printf("Queue에 데이터를 삭제합니다.\n");
for(i=0; i<2; i++)
{
DeQueue();
}
Print_Queue();
//스택 비움
printf("Queue를 비웁니다..\n");
All_Clear();
Print_Queue();
return 0;
}
void init_Queue()
{
rear=-1;
front=-1;
}
void InQueue()
{
int num;
rear+=1;
if(rear>=5)
{
printf("Overflow!\n");
}
else
{
printf("Input : ");
scanf("%d",&num);
ary[rear]=num;
}
}
void DeQueue()
{
front+=1;
if(front==rear)
{
printf("underflow!\n");
All_Clear();
}
else{
ary[front]=0;
}
}
void Print_Queue()
{
int i;
for(i=0; i<5; i++)
{
printf("Queue Data : %3d\n",ary[i]);
}
printf("\n");
}
void All_Clear()
{
int i;
for(i=0; i<5; i++)
{
ary[i]=0;
}
init_Queue();
[알고리즘] 2월 첫째주 알고리즘 - 3n+1 (0) | 2012.02.03 |
---|---|
[C언어] 2차원 배열 - 달팽이 알고리즘 - (0) | 2012.02.03 |
먼저 소스를 보여드리기에 앞서, 달팽이 알고리즘에 대해 설명해드릴게요.
1 2 3 1 2 3 4 1 2 3 4 5
8 9 4 12 13 14 5 16 17 18 19 6
7 6 5 11 16 15 6 15 24 25 20 7
10 9 8 7 14 23 22 21 8
13 12 11 10 9
x3 x4 x5
#include <stdio.h>
int main()
{
int ary[50][50];
int n, z, i, j, x=0, y=-1, turn=1;
int num=1;
printf("숫자입력 : ");
scanf("%d",&n);
z=n;
while(z!=0)
{
for(i=0; i<z; i++)
{
y+=turn;
ary[x][y]=num;
num++;
}
z--;
for(i=0; i<z; i++)
{
x+=turn;
ary[x][y]=num;
num++;
}
turn*=-1;
}
for(i=0; i<n; i++)
{
for(j=0; j<n;j++)
{
printf("%5d",ary[i][j]);
}
printf("\n");
}
return 0;
}
[알고리즘] 2월 첫째주 알고리즘 - 3n+1 (0) | 2012.02.03 |
---|---|
[C언어] 배열과 함수만을 이용한 Queue (0) | 2012.02.03 |