VioletaBabel

10845번: 큐 본문

백준/백준-C
10845번: 큐
Beabletoet 2017. 4. 21. 11:14

#include <stdio.h>

#include <stdlib.h>

#include <string.h>


int q[10000];

int start = 0, end = 0, count = 0;


void push(int x);

void pop();

void size();

void empty();

void front();

void back();


void push(int x)

{

q[end++] = x;

++count;

}

void pop()

{

if (count != 0)

{

printf("%d\n", q[start++]);

--count;

}

else

printf("-1\n");

}

void size()

{

printf("%d\n", count);

}

void empty()

{

if (count == 0)

printf("1\n");

else

printf("0\n");

}

void front()

{

if (count != 0)

printf("%d\n", q[start]);

else

printf("-1\n");

}

void back()

{

if (count != 0)

printf("%d\n", q[end-1]);

else

printf("-1\n");

}

int main()

{

int N;

scanf("%d", &N);

for (int i = 0; i < N; ++i)

{

char command[6];

int x;

scanf("%s", &command);

if (!strcmp(command, "push"))

{

scanf("%d", &x);

push(x);

}

else if (!strcmp(command, "pop"))

pop();

else if (strcmp(command, "size") == 0)

size();

else if (strcmp(command, "empty") == 0)

empty();

else if (strcmp(command, "front") == 0)

front();

else if (strcmp(command, "back") == 0)

back();

}

}

'백준 > 백준-C' 카테고리의 다른 글

2750번: 수 정렬하기  (0) 2017.05.02
11866번: 조세퍼스 문제  (0) 2017.04.25
9012번: 괄호  (0) 2017.04.20
1874번:스택 수열  (0) 2017.04.19
10828번: 스택  (0) 2017.04.19
Comments