원형큐인데 좀 봐주세요~
진이
제가 작성한건데요 경고가 뜨면서 안되네요~ 빨간색으로 표시해났습니다~
실행 메뉴는 총 4개
① 입력 (push) : 데이터 삽입
② 삭제 (pop) : 데이터 삭제
③ 보기 (queue의 마지막 인덱스에서 막힘없이 처음 인덱스로 구현되는 모습을 보여주면 댐)
④ 종료 (프로그램 종료)
입력시에 대한 사항 : 메뉴 입력시에 정의 되어 있지 않는 데이터에 대한 오류 검출 기능 추가 요망
보기 에 대한 메뉴 구현은 아래의 규칙을 기본적으로 구현 할것
1) 메뉴 선택시에 하나씩 보여주며, 다음것을 계속 보게 하여, 한바퀴를 돌아서 다시 보게 되게 구현질문 내용 :
#includestdio.h
#includemalloc.h
typedef struct
{
char name[10];
int id;
char number[20];
}element;
typedef struct
{
element item;
struct queuenode *link;
}queuenode;
typedef struct
{
queuenode *front, *rear;
}queuelink;
int count=0;
void error(char *mess)
{
fprintf(stderr,%s\n,mess);
}
void init(queuelink *q)
{
q-front=q-rear=null;
}
int is_empty(queuelink *q)
{
return (q-front==null);
}
void enqueue(queuelink *q,element item)
{
queuenode *temp=(queuenode*)malloc(sizeof(queuenode));
if(temp=null)
error(할당에러);
else if(count9)
error(10초과됐다);
else{
temp-item=item;
temp-link=null;
if(is_empty(q)){
q-front=temp;
q-rear=temp;
count++;
}
else{
q-rear-link=temp; //queuenode*와queuenode*사이의 형식이 호환되지 안된다고 하네요~
q-rear=temp;
count++;
}
}
}
element dequeue(queuelink *q)
{
queuenode *temp=q-front;
element item;
if(is_empty(q))
error(큐가 비어져있습니다);
else{
item=temp-item;
q-front=q-front-link; //queuenode*와queuenode*사이의 형식이 호환되지 안된다고 하네요~
if(q-front==null)
q-rear=null;
count--;
free(temp);
return item;
}
}
int main()
{
queuelink tenq;
int num;
element a;init(&tenq);
while(1)
{
printf(1.입력\n);
printf(2.삭제\n);
printf(3.보기\n);
printf(4.종료\n);
printf(메뉴선택\n);
scanf(%d, &num);
if(num==4)
break;
else if(num==1){
printf(이름 : );
scanf(%s,&a.name);
printf(학번 : );
scanf(%d,&a.id);
printf(전화번호 : );
scanf(%s,&a.number);
enqueue(&tenq,a);
}
else if(num==2){
dequeue(&tenq);
}
else if(num==3){
while(count0){
printf(----------------------------);
printf(%s,tenq.front-item.name);
printf(%d,tenq.front-item.id);
printf(%s,tenq.front-item.number);
printf(----------------------------);
tenq.front=tenq.front-link; //queuenode*와queuenode*사이의 형식이 호환되지 안된다고 하네요~
count--;
}
}
else
printf(잘못입력했습니다);
}
return 0;
}
-
발랄한그1녀
typedef struct == typedef struct _queuenode
{
element item;
struct queuenode *link; == struct _queuenode *link;
}queuenode;
void enqueue(queuelink *q,element item)
{
queuenode *temp=(queuenode*)malloc(sizeof(queuenode));
if(temp=NULL) == if(temp
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2697401 | 열혈강의 문제오류 (1) | 꿈 | 2025-06-07 |
2697374 | 기초적인 C언어 프로그래밍 입니다. | 얼 | 2025-06-07 |
2697341 | 좌우대칭 문제인데 Q가 입력되면 종료가 되야하는데 되지않습니다 | 무지개 | 2025-06-07 |
2697314 | fprintf와 fscanf 로 파일 입출력 할떄 | 밝음이 | 2025-06-06 |
2697293 | 툴 소스 뽑아내는법 | 도움 | 2025-06-06 |
2697264 | 소소한거 두어가지 질문할께요~ (8) | 별솔 | 2025-06-06 |
2697235 | scanf로 인풋 받을 때?! | 보담 | 2025-06-06 |
2697207 | 열혈강의 연습문제 질문이요~ (2) | 맥적다 | 2025-06-05 |
2697182 | strcmp, strtok - 어떤 기능을 하는지... | 루다 | 2025-06-05 |
2697129 | [질문] 아래 저축액을 계산하는 프로그램 ㅠ 추가 질문 (7) | 찬늘 | 2025-06-05 |
2697072 | 쌩초보 질문! (1) | 얀 | 2025-06-04 |
2697050 | 도움부탁드립니다.. | 화이트 | 2025-06-04 |
2697023 | gotoxy함수, 어떻게 사용하죠? (3) | 적송 | 2025-06-04 |
2696994 | c언어를 막 시작한 초보인데 질문이 있어용 ㅠㅠ (2) | 귀1여운렩 | 2025-06-03 |
2696944 | 윈도우 콘솔프로그램 질문드립니다 (2) | 꽃님이 | 2025-06-03 |
2696882 | c언어 입력받기 질문 입니다 (2) | 흰추위 | 2025-06-02 |
2696853 | 문자열은 정적메모리에 할당된다고 하는데 정적메모리가 뭡니까?? (6) | 다온 | 2025-06-02 |
2696799 | c c++언어입문전에 파이톤이나 자바스크립트배워두면.. (2) | 앨런 | 2025-06-02 |
2696747 | size of 연산자에 대해 질문이 있습니다. (3) | 유진공주 | 2025-06-01 |
2696721 | Char 타입의 2D array 기초에 대해 질문드립니다. | 벚꽃 | 2025-06-01 |