오늘 마지막 큐 질문
헛장사
아래의 프로그램을 완성하여 다음의 연결된 큐를 완성하시오
front rear
A link - B link - C link - D link - NULL
#include stdio.h
#include malloc.h
#include stdlib.h
typedef int element;
typedef struct QueueNode {
element item;
struct QueueNode *link;
} QueueNode;
typedef struct {
QueueNode *front, *rear;
} QueueType;
void error(char *message)
{
fprintf(stderr,%s\n,message);
exit(1);
}
void init(QueueType *q)
{
q-front = q-rear = NULL;
}
int is_empty(QueueType *q)
{
return (q-front==NULL);
}
int is_full(QueueType *q)
{
return 0;
}
void enqueue(QueueType *q, element item)
{
QueueNode *temp = (QueueNode *)malloc(sizeof(QueueNode));
if(temp == NULL)
error(메모리를 할당할 수 없습니다.);
else
{
temp-item =item;
temp-link =NULL;
if(is_empty(q)){
q-front = temp;
q-rear = temp;
}
else{
q-rear-link = temp;
q-rear = temp;
}
}
}
element dequeue(QueueType *q)
{
QueueNode *temp = q-front;
element item;
if(is_empty(q))
{
error(큐가 비어 있습니다.);
return 0;
}
else
{
item = temp-item;
q-front = q-front-link;
if(q-front == NULL)
q-rear = NULL;
free(temp);
return item;
}
}
element peek(QueueType *q)
{
if(is_empty(q))
{
error(큐가 비어 있습니다.);
return 0;
}
else
{
element item = q-front-item;
return item;
}
}
int main()
{
QueueType q;
init(&q);
QueueNode *front, *rear;
front = rear = NULL;
enqueue(&q, 1);
enqueue(&q, 2);
enqueue(&q, 3);
enqueue(&q, 4);
printf(A()=%dn, dequeue(&q));
printf(B()=%dn, dequeue(&q));
printf(C()=%dn, dequeue(&q));
printf(D()=%dn, dequeue(&q));
}
제가 정말 미칠듯이 해서 만들었는데
맞게 했는지 좀 봐주세요~!!
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700900 | 반복문 도움요청..!!합니다. (1) | 두힘 | 2025-07-09 |
2700875 | (유효성검사)프로그램 짜는데 질문이 잇습니다. | 휑하니 | 2025-07-09 |
2700852 | 링크드 리스트 구현시 malloc 관련 에러 입니다. | 삐용삐용 | 2025-07-08 |
2700828 | 7/4 와 7/4.0 의 차이 | 발랄한그1녀 | 2025-07-08 |
2700771 | 아스키값 질문입니다. (+추가 임베디드 다른것도!) (3) | 찰스 | 2025-07-08 |
2700746 | 코드 오류 질문드립니다 | 차분 | 2025-07-07 |
2700721 | 배열 프로그래밍 입니다. (1) | 크나 | 2025-07-07 |
2700695 | 간단한 메모장 구현을 할려고 하는데요 (9) | 늘솜 | 2025-07-07 |
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |