실행이 안되요..ㅠㅠ
여신
질문 제목 : 잘못된 부분점 찾아주세요 ㅠㅠ;다른건 문제 없는것 같구 del함수가 문제임질문 내용 : 다른건 문제 없는것 같구 del함수가 문제인데용
del은int val을 받아서 구조체 node의data가val과 같으면 지워버리는 함수에용
연결리스트 이구요 ㅋㅋㅋ
그리구 쓸데없는 부분이 있으면 그 부분도 지적해주시면 새겨 듣겟슴니다 ㅋㅋ 답변 부탁드려요 ~ ㅎㅎ
오류나 경고는 안드는데 실행에서 디버깅오류?? 그런게 뜨네요 ㅠㅠ
#includestdio.h
#includestdlib.h
struct node
{
int data;
struct node* next;
};
struct node* pstart=null;
struct node* pend=null;
void del(int val)
{
int i=0;
struct node* pnode=pstart;
struct node* pdelnode=null;
pnode=(struct node*)malloc(sizeof(struct node));
pdelnode=(struct node*)malloc(sizeof(struct node));
while(pnode-next != null)
{
if(pnode-next-data == val){
pdelnode=pnode-next;
pnode-next=pdelnode-next;
free(pdelnode);
}
pnode=pnode-next;
}
}
void addrear(int val)
{
struct node* current=null;
current=(struct node*)malloc(sizeof(struct node));
current-data=val;
current-next=null;
if(pstart==null){
pstart=pend=current;
}
else{
pend-next=current;
pend=current;
}
}
void addfront(int val)
{
struct node* current=null;
current=(struct node*)malloc(sizeof(struct node));
current-data=val;
current-next=null;
if(pstart==null){
pstart=pend=current;
}
else{
current-next=pstart;
pstart=current;
}
}
void printlist(struct node* current)
{
while(current!=null)
{
printf(%d\n, current-data);
current=current-next;
}
}
int main(void)
{
int i;
for(i=1;i=5;i++){
addfront(i);
}
del(3);
del(1);
printlist(pstart);
return 0;
}
-
슬S2아 2024-08-09
링크드리스트 삭제 함수에서 malloc함수를 사용하는 것을 처음 봤습니다.
이미 존재하는 링크드리스트에서 검색을 해서 삭제시켜야 하는거 아닌가요?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694069 | unsigned 질문입니다. | 힘차 | 2025-05-07 |
2694012 | 전공 비전공자 개발자 (10) | 말글 | 2025-05-07 |
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |
2693591 | 컴파일 에러에서 질문드립니다 (3) | 게자리 | 2025-05-03 |
2693463 | 동적할당 이용시 fwrite사용을 어떻게 해야하나요..? (10) | 일본어못해요 | 2025-05-02 |
2693387 | 배열문제입니다 수정오류캡쳐했습니다 (6) | 연하얀 | 2025-05-01 |
2693356 | text 입출력 내림차순 질문입니다 ㅠ | 빛글 | 2025-05-01 |