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;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |