/*#include<stdio.h>
#include <string.h>
int stack[300]= {};
int top=-1;
void push(int data)
{
stack[++top]=data;
}
int pop()
{
if(top!=-1)
{
return stack[top--];
}
}
int main()
{
char a[102]= {};
char b[102]= {};
int k=0;
int x, y;
int p, q;
scanf("%s %s", a, b);
x = strlen(a)-1;
y = strlen(b)-1;
for(;;)
{
p = a[x]-'0';
q = b[y]-'0' ;
push((k+p+q)%10);
k = (k+p+q)/10;
x--;
y--;
if(x<0 || y<0)
{
break;
}
}
if(x==-1&&y!=-1)
{
for(;;)
{
push((k+b[y]-'0')%10);
k=(k+b[y]-'0')/10;
if(y==0)
{
break;
}
y--;
}
}
else if(y==-1 && x!=-1)
{
for(;;)
{
push((k+a[x]-'0')%10);
k=(k+a[x]-'0')/10;
if(x==0)
{
break;
}
x--;
}
}
if(k!=0) push(k);
for(; top>=0; top--)
{
printf("%d", stack[top]);
}
}
자료구조
정렬1 ㅇ
스택 ㅇ
큐
이분탐색
정렬2 - 퀵정렬
DFS/BFS
*/
/*
#include<stdio.h>
#include <string.h>
int queue[300]= {};
int front=-1, rear=-1;
void enqeue(int data)
{
queue[++rear]=data;
}
int dequeue()
{
if(rear == front)
{
return queue[++front];
}
}
int main()
{
}
*/
#include<stdio.h>
#include <string.h>
#define SIZE 7
int queue[SIZE]= {};
int front=-1, rear=-1;
void enqueue(int data)
{
rear=(rear+1)%SIZE;
queue[rear]=data;
}
int dequeue()
{
if(rear != front)
{
front=(front+1)%SIZE;
return queue[front];
}
}
int main()
{
int a, b, c;
int sum=0;
while(1)
{
printf("1. enqueue \ 2. dequeue \ 3. view \ 4. stop >> ");
scanf("%d",&a);
if(a==1)
{
if(rear==6)
{
printf("큐 저장량이 꽉 찼습니다 enqueue 불가능!!\n");
continue;
}
printf("enqueue할 데이터를 입력하세요 >> ");
scanf("%d",&b);
enqueue(b);
}
else if(a==2)
{
if(rear==front)
{
printf("큐가 비었습니다! dequeue 불가능!\n");
continue;
}
else
{
dequeue();
}
}
else if(a==4)
{
printf("exit 키를 눌렀습니다. 창을 닫습니다.");
break;
}
else
{
printf("queue >> ");
for(int i=front+1; i<=rear; i++)
printf("%d ",queue[i]);
printf("\n");
}
}
}



