자료구조 - 원형연결리스트에 관한 질문입니다.
도담
질문 제목 : 자료구조 원형연결리스트 삽입에 관한 질문
자료구조 - 원형연결리스트 , insert first node ,화면출력에 관련된 질문,
질문 내용 :
단순연결리스트를 구현해본후 원형연결리스트를 구현해보려고 하고있는데, 도무지 진도가 나가지 않아서 질문합니당 . 초기화할때 잘못된건지.. insertfirstnode 구현이 잘못된건지 화면에 출력하면 자료에 입력이 되지 않은상태초기화된 상태랑 똑같이 화면에 찍히는데어디서잘못된건지 갈피를못잡겠습니다..소스를 보시고.. 어느부분이 잘못된건지좀 알려주세용..- 소스내용이고 현재는 insert first node와 화면에 출력하는것만 구현한 상태입니다.
#include stdio.h
#include stdlib.h
#include string.h
typedef struct listnode{
char data[10];
struct listnode* link;
} listnode;
typedef struct{
listnode* head;
} linkedlist_h;
linkedlist_h* createlinkedlist_h(void);
void freelinkedlist_h(linkedlist_h*);
void insertfirstnode(linkedlist_h*, char*);
void printlist(linkedlist_h*);
linkedlist_h* createlinkedlist_h(void)
{
linkedlist_h* cl;
cl = (linkedlist_h*)malloc(sizeof(linkedlist_h));
cl - head = null;
return cl;
}
void insertfirstnode(linkedlist_h* cl, char* x)
{
listnode* newnode;
listnode* p;
newnode = (listnode*)malloc(sizeof(listnode));
strcpy(newnode-data,x);
if(cl-head == null){
cl-head = newnode;
newnode-link = newnode;
return;
}
else
{
p = cl-head;
while(p-link != cl-head)
{
p = p-link;
}
newnode-link = p-link;
p-link = newnode;
cl-head = newnode;
}
}
void printlist(linkedlist_h* cl){
listnode* p;
printf(cl = ();
p = cl-head;
while(p != cl-head ){
printf(%s, p-data);
p = p-link;
if(p != cl-head){
printf(,);
}
}
printf() \n);
}
int main()
{
linkedlist_h* cl;
cl = createlinkedlist_h();
printf((1) 공백 리스트 생성하기! \n);
printlist(cl);
getchar();
printf((2) 리스트 처음에 노드 한개 추가하기! \n);
insertfirstnode(cl,일);
insertfirstnode(cl,토);
insertfirstnode(cl,금);
insertfirstnode(cl,목);
insertfirstnode(cl,수);
insertfirstnode(cl,화);
insertfirstnode(cl,월);
printlist(cl);
getchar();
return 0;
}
-
공주
typedef struct{
listNode* head;
} linkedList_h;
이렇게 구조체를 만들면 프로그램이 엄청 복잡합니다.
그냥
listNode* head;
이렇게 밖으로 빼고 해 보세요.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |