단일링크드리스트 큐 구현한건데요..ㅠㅠ
모아
지금 자료구조 단일링크드리트드로 큐를 구현하는걸 제가 짜본건데요...
거의 다 된듯싶은데 거의다 완성됐는데 자꾸 에러가 떠버리네요...
돌아가다가도 막 이것저것 넣어보면 에러나버리고...
이걸로 몇시간을 끌고있는지... 도움좀 부탁드립니다..
#include stdio.h
#include stdlib.h
#include conio.h
typedef struct lister{
int number;
struct lister *link;
}node;
node *head, *front, *rear;
void menu(void);
void enqueue(int);
void dequeue(void);
void display(void);
main()
{
int input;
int num;
front = (node *)malloc(sizeof(node));
rear = (node *)malloc(sizeof(node));
front = rear;
rear-link = NULL;
while(1)// 막돌려
{
menu();
scanf(%d,&num);
switch(num)
{
case 1:
printf(넣고자하는 값을 입력 : );
scanf(%d,&input);
enqueue(input);
printf(\n지금 들어 있는 값들 : );
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(1);
}
}
}
void enqueue(int a)
{
node *temp;
temp = (node*)malloc(sizeof(node));
if(front == NULL)
{
front=(node*)malloc(sizeof(node));
front-link=NULL;
rear=front;
}
else
{
temp=(node*)malloc(sizeof(node));
temp-number = a;
rear-link = temp;
rear=temp;
}
}
void dequeue(void){
node *temp;
temp = (node*)malloc(sizeof(node));
printf(삭제된값은 : %d 입니다..,front-link-number);
temp = front;
front-link = front;
free(temp);
}
void display(void)
{
node *temp;
temp = (node*)malloc(sizeof(node));
temp = front-link; //이부분은 왜 그냥 front가아니라 front-link를 해줘야하는지..걍 프런트하니깐
//첫번째값에 쓰레기값이 나오더군요.. 왜그런지;;ㅠㅠ
while(1)
{
printf(%d ,temp-number);
temp = temp-link;
if(temp rear)
return;
}
}
void menu(void)
{
printf(\n----메뉴----\n);
printf(-- 1.삽입 --\n);
printf(-- 2.삭제 --\n);
printf(-- 3.출력 --\n);
printf(-- 4.종료 --\n);}
-
우미
솔직히 소스 진짜 불필요하게 짜신듯...
-
콘라드
node *head;
이 변수는 언제 사용하죠?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655576 | 구조체 선언 질문입니다. | 통꽃 | 2024-05-21 |
2655547 | 변수선언과 printf만 사용해서 수식 짜기 (1) | 피리 | 2024-05-20 |
2655523 | 문자열 사이에 문자열삽입 | 바람 | 2024-05-20 |
2655491 | 키보드 인식, 랜덤 함수 or 헤더 (2) | 별 | 2024-05-20 |
2655471 | 링 버퍼 구현된 소스 인데요.. 이해가 잘안되서요.. | 소심한녀자 | 2024-05-20 |
2655440 | test파일이 안 되요. (2) | 리라 | 2024-05-19 |
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |