linkedList 삽입문제 질문이요
꽃
질문 제목 : 월이랑 수 사이에 화요일삽입질문 내용 :
월요일이랑 수요일사이에 화요일삽입하는건데요...
어떻게해야되나요? 함수를이용해서 삽입하라고하랬는데
어떻게해야할지모르겠습니다.. 저건 막한거구요...(밑줄친거)
link주소를 temp에두고 뭐.... 이렇게하랫던거같은데 모르겠네요 ㅠㅠ
도와주세요
#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 addlastnode(linkedlist_h*,char*);
void reverse(linkedlist_h*);
void deletelastnode(linkedlist_h*);
void printlist(linkedlist_h*);
void intput(linkedlist_h*,char*);
linkedlist_h* createlinkedlist_h(void)
{
linkedlist_h*l;
l=(linkedlist_h*)malloc(sizeof(linkedlist_h));
l-head=null;
return l;
}
void addlastnode(linkedlist_h*l,char *x)
{
listnode * newnode;
listnode*p;
newnode = (listnode*)malloc(sizeof(listnode));
strcpy(newnode-data,x);
newnode -link=null;
if(l-head==null)
{
l-head = newnode;
return;
}
p=l-head;
while(p-link!=null)
p=p-link;
p-link=newnode;
}
void reverse(linkedlist_h*l)
{
listnode *p;
listnode*q;
listnode*r;
p=l-head;
q=null;
r=null;
while(p!=null)
{
r=q;
q=p;
p=p-link ;
q-link=r;
}
l-head=q;
}
void deletelastnode(linkedlist_h *l)
{
listnode *previous;
listnode * current;
if(l-head == null)
return ;
if(l-head-link == null)
{
free(l-head);
l-head=null;
return;
}
else
{
previous =l-head;
current=l-head-link;
while(current -link !=null)
{
previous = current;
current=current-link;
}
free(current);
previous-link=null;
}
}
void freelinkedlist_h(linkedlist_h*l)
{
listnode *p;
while(l-head !=null)
{
p=l-head;
l-head = l-head-link;
free(p);
p=null;
}
}
void printlist(linkedlist_h*l)
{
listnode *p;
printf(l=();
p=l-head;
while(p!=null)
{
printf(%s,p-data);
p=p-link;
if(p!=null)
printf(,);
}
printf()\n);
}
void intput(linkedlist_h*l,char*x)
{
listnode * newnode;
listnode*i;
newnode = (listnode*)malloc(sizeof(listnode));
strcpy(newnode-data,x);
if(l-head==null)
{
l-head=newnode;
}
else
{
i=l-head;
while(i-link!=null)
i=i-link;
i-link=newnode;
newnode=i;
}
}
int main()
{
linkedlist_h*l;
l=createlinkedlist_h();
printf((1)공백 리스트 생성하기 !\n);
printlist(l);
getchar();
printf((2)리스트에 3개의 노드 추가하기!煞′歐?\n);
addlastnode(l,월);
addlastnode(l,수);
addlastnode(l,금);
printlist(l);
getchar();
printf((22)화요일삽입하기 \n);
intput(l,화);
printlist(l);
getchar();
printf((3)리스트 마지막에 노드 한개추가하기! \n);
addlastnode(l,일);
printlist(l);
getchar();
printf((4)마지막 노드 삭제하기!\n);
deletelastnode(l);
printlist(l);
getchar();
printf((5)리스트 원소를 역순으로 변환하기! \n);
reverse(l);
printlist(l);
getchar();
printf((7)리스트공간을 해제,공백리스트 상태만들기!\n);
freelinkedlist_h(l);
printlist(l);
getchar();
return 0;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695766 | 달팽이 배열 어디서 틀렸는지 모르겠습니다ㅠㅠ | 연분홍 | 2025-05-23 |
2695738 | fopen과fclose질문~~ (5) | 희선 | 2025-05-23 |
2695707 | 3의 배수 나타내기. (2) | 수리 | 2025-05-23 |
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |