회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
런타임에러가 뜹니다.
10866번 - 덱
geunwoong0624
5년 전
0
런타임에러가 뜹니다. 이유가 무엇인지 궁금합니다.
#include <stdio.h> #include <stdlib.h> struct Queue { struct list * front; struct list * rear; }; struct list { struct list * Next_link; struct list * Past_link; int item; }; void push_front_X(struct Queue *root,int Newitem) { struct list * Newnode = (struct list*)malloc(sizeof(struct list)); Newnode->item = Newitem; if (root->front == NULL) { root->front = Newnode; root->rear = Newnode; Newnode->Next_link = NULL; Newnode->Past_link = NULL; }//아무것도 없음 else { Newnode->Next_link = root->front; root->front->Past_link = Newnode; Newnode->Past_link = NULL; root->front = Newnode; }//1개 이상 } void push_back_X(struct Queue *root, int Newitem) { struct list * Newnode = (struct list*)malloc(sizeof(struct list)); Newnode->item = Newitem; if (root->front == NULL) { root->front = Newnode; root->rear = Newnode; Newnode->Next_link = NULL; Newnode->Past_link = NULL; }//아무것도 없음 else { Newnode->Past_link = root->rear; root->rear->Next_link = Newnode; Newnode->Next_link = NULL; root->rear = Newnode; }//1개이상 } void pop_front_X(struct Queue *root) { if (root->front == NULL) { printf("-1\n"); }//비어있음 else if (root->front == root->rear) { struct list *p = root->front; root->front = NULL; root->rear = NULL; printf("%d\n", p->item); free(p); }//1개있음 else { struct list *p = root->front; root->front = p->Next_link; root->front->Past_link = NULL; printf("%d\n", p->item); free(p); }//2개이상 } void pop_back_X(struct Queue *root) { if (root->front==NULL) { printf("-1\n"); }//비어있음 else if (root->front == root->rear) { struct list *p = root->rear; root->front = NULL; root->rear = NULL; printf("%d\n", p->item); free(p); }//1개있음 else { struct list *p = root->front; root->rear = p->Past_link; root->rear->Next_link = NULL; printf("%d\n", p->item); free(p); } } void Deque_size(struct Queue *root) { int num = 0; for (struct list *p = root->front; p != NULL; p = p->Next_link) { num++; } printf("%d\n", num); } void Deque_empty(struct Queue *root) { if (root->front == NULL) { printf("1\n"); } else { printf("0\n"); } } void Deque_front(struct Queue *root) { if (root->front == NULL) { printf("-1\n"); } else { printf("%d\n", root->front->item); } } void Deque_back(struct Queue *root) { if (root->rear == NULL) { printf("-1\n"); } else { printf("%d\n", root->rear->item); } } int main(void) { int Case = 0; scanf("%d", &Case); struct Queue *root = (struct Queue*)malloc(sizeof(struct Queue)); root->front = NULL; root->rear = NULL; for (int i = 0; i < Case; i++) { char Array[11] = { 0, }; scanf("%s", Array); if (Array[0] == 'p') { if (Array[1] == 'u') { int X = 0; if (Array[5] == 'f') { scanf("%d", &X); push_front_X(root,X); }//push_front X : 정수 X를 덱의 앞에 넣는다. else { scanf("%d", &X); push_back_X(root, X); }//push_back X : 정수 X를 덱의 뒤에 넣는다. } else { if (Array[4] == 'f') { pop_front_X(root); }//pop_front: 덱의 가장 앞에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. else { pop_back_X(root); }//pop_back: 덱의 가장 뒤에 있는 수를 빼고, 그 수를 출력한다. 만약, 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. } } else if (Array[0] == 's') { Deque_size(root); }//size: 덱에 들어있는 정수의 개수를 출력한다. else if (Array[0] == 'e') { Deque_empty(root); }//empty: 덱이 비어있으면 1을, 아니면 0을 출력한다. else if (Array[0] == 'f') { Deque_front(root); }//front: 덱의 가장 앞에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. else if (Array[0] == 'b') { Deque_back(root); }//back: 덱의 가장 뒤에 있는 정수를 출력한다. 만약 덱에 들어있는 정수가 없는 경우에는 -1을 출력한다. } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
geunwoong0624 5년 전
런타임에러가 뜹니다. 이유가 무엇인지 궁금합니다.