기수정렬 관련 코딩 버켓의 내용을 출력하라는데...
티나
질문 제목 : 기수정렬 프로그램을 버켓의내용을 화면에 출력하래요.버켓의 내용출력질문 내용 : 버켓의 내용을 어떻게 구현해야 할지 모르겠습니당..
#includestdio.h
#define max_queue_size 100
#define buckets 10
#define digits 4
typedef int element;
typedef struct {
element queue[max_queue_size];
int front, rear;
} queuetype;
void error(char *message)
{
fprintf(stderr,%s\n,message);
exit(1);
}
void init(queuetype *q)
{
q-front = q-rear = 0;
}
int is_empty(queuetype *q)
{
return (q-front == q-rear);
}
int is_full(queuetype *q)
{
return ((q-rear+1)%max_queue_size == q-front);
}
void enqueue(queuetype *q, element item)
{
if( is_full(q) )
error(큐가 포화상태입니다);
q-rear = (q-rear+1) % max_queue_size;
q-queue[q-rear] = item;
}
element dequeue(queuetype *q)
{
if( is_empty(q) )
error(큐가 공백상태입니다);
q-front = (q-front+1) % max_queue_size;
return q-queue[q-front];
}
element peek(queuetype *q)
{
if( is_empty(q) )
error(큐가 공백상태입니다);
return q-queue[(q-front+1) % max_queue_size];
}
void printf_bucket(int list[], int n)
{
int i, b , d, factor=1;
queuetype queues[buckets];
for(b=0;bbuckets;b++) init(&queues[b]);
for(d=0; ddigits; d++){
for(i=0;in;i++)
enqueue( &queues[(list[i]/factor)%10], list[i]);
for(b=i=0;bbuckets;b++)
while( !is_empty(&queues[b]) )
list[i++] = dequeue(&queues[b]);
factor *= 10;
}
}
void main()
{
queuetype q;
init(&q);
printf(front=%d rear=%d\n,q.front, q.rear);
enqueue(&q, 1);
enqueue(&q, 2);
enqueue(&q, 3);
enqueue(&q, 4);
enqueue(&q, 5);
enqueue(&q, 6);
enqueue(&q, 7);
enqueue(&q, 8);
enqueue(&q, 9);
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(dequeue()=%d\n,dequeue(&q));
printf(front=%d rear=%d\n,q.front, q.rear);
}
책보고 이런식으로 만들었는데요....
[0]- 0
[1]-
[2]- 62
[3]-
[4]- 64 24 34
[5]-
[6]-
[7]-
[8]- 58 78
[9]- 69
이렇게 출력되야 하는데 어떻게해야할까요............
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698120 | -연산자 가 먼지 좀 알려주세요 (1) | 낮선검객 | 2025-06-14 |
2698091 | 길찾기문제 질문이요! | 노을빛 | 2025-06-13 |
2698060 | while 문에 대한 질문입니다. (9) | 물고기자리 | 2025-06-13 |
2698012 | 2~9가아닌수 | 아놀드 | 2025-06-13 |
2697980 | for에 gets함수를 넣으니까 왜 반복이 안되죠 ㅜ (2) | 펴라 | 2025-06-12 |
2697952 | 2차배열과 함수문의^^; | VanilLa | 2025-06-12 |
2697924 | 다차원 배열 질문있습니다 | 두동 | 2025-06-12 |
2697893 | 정올 :: 기초다지기 a9007 배열7 (문제가 이상함 -_-) | 흰두루 | 2025-06-12 |
2697862 | Unable......... 지정된 파일을 찾을 수 없습니다!! (1) | Creator | 2025-06-11 |
2697761 | 그러니까여제말은... (2) | 새론 | 2025-06-10 |
2697737 | 정올 문제좀 풀어보신분~ | 레오 | 2025-06-10 |
2697709 | rand함수 질문좀요! (6) | 가막새 | 2025-06-10 |
2697683 | C언어 변수뒤 표시가 이해안되는게 있습니다. | 소미 | 2025-06-10 |
2697660 | 껍데기딜 만들고 난후 어느핫키 누르면 코드검색이라도 뜨고 그다음 무반응 해결좀 (2) | 움찬 | 2025-06-09 |
2697634 | c언어로 감성사전 만들기! (1) | 도란도란 | 2025-06-09 |
2697605 | 이 함수좀... | agine | 2025-06-09 |
2697574 | 배열 기본적인질문 (3) | 민트향 | 2025-06-09 |
2697549 | 배열 초기화 (4) | 나리 | 2025-06-08 |
2697465 | 수다님...^^ (2) | 가론 | 2025-06-08 |
2697432 | 서버 만드는 함수에서 궁금한게있어요~ | 파랑 | 2025-06-07 |