연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다.
딥블랙
질문 제목 : 연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다. 질문 내용 :
listp.h입니다.
struct node
{
int data; //노드 내부의 실제 데이터 또는 레코드
struct node* next; //next가 가리키는 것은 node 타입, 즉 자기 자신 타입
}; //구조체에 node라는 새로운 타입명 부여
typedef struct node node;
typedef node* nptr; //nptr 타입이 가리키는 것은 node 타입
struct listtype
{
int count; //리스트 길이를 추적
nptr head; //헤드 포인터로 리스트 전체를 대변함
};
typedef struct listtype listtype;
void insert(listtype *lptr, int position, int item); //해당 위치에 데이터를 삽입
void delete(listtype *lptr, int position); //해당 위치 데이터를 삭제
void retrieve(listtype *lptr, int position, int *itemptr); //찾은 데이터를 *itemptr에 넣음
void init(listtype *lptr); //초기화
int isempty(listtype *lptr); //비어있는지 확인
int length(listtype *lptr);listp.c입니다.
#include stdio.h
#include stdlib.h
#include time.h
#include listp.h
void insert(listtype *lptr, int position, int item)//해당 위치에 데이터를 삽입
{int i;
nptr temp;
if((position (lptr-count+1)) || (position1))
printf(position out of range);
else
{
nptr p=(node *)malloc(sizeof(node));
p-data = item;
if(position ==1)
{
p-next = lptr-head;
lptr-head = p;
}
else
{
temp = lptr-head;
for(i=1; i(position-1);i++)
temp=temp-next;
p-next = temp-next;
temp-next = p;
}
lptr-count ++;
}
}
void delete(listtype *lptr, int position) //해당 위치 데이터를 삭제
{int i;
nptr p;
if(isempty(lptr))
printf(deletion on empty list);
else if (position (lptr-count) || (position1))
printf(position out of range);
else
&nbnbsp; {
if(position==1)
{
p=lptr-head;
lptr-head=lptr-head-next;
}
else
{
nptr temp = lptr-head;
for(i=1; i (position-1) ; i++)
temp = temp-next;
p = temp-next;
temp-next = p-next;
}
lptr-count --;
free (p);
}
}
void retrieve(listtype *lptr, int position, int *itemptr)
{ int i=1;
nptr tmp=lptr-head;
while(tmp!=null)
{
if(position==tmp-data)
break;
i++;
tmp=tmp-next;
}
if(ilptr-count)
{
printf(the data %d is not exists\n,position);
}
else
{ itemptr=&tmp-data;
printf(the data %d is at position %d in the list\n,position,i);
}
} //찾은 데이터를 *itemptr에 넣음
void init(listtype *lptr) //초기화
{
lptr-count=0;
lptr-head=null;
}
int isempty(listtype *lptr) //비어있는지 확인
{
return (lptr-count ==0);
}
int length(listtype *lptr)
{
return (lptr-count);
}main.c입니다.
#include stdio.h
#include stdlib.h
#include time.h
#include listp.h
int main(void)
{
int i=73;
struct listtype *list=null;
nptr p;
p=(node *)malloc(i*sizeof(node));
srand(time(null));
list-head=p;
printf(임의의 값을 가지는 73개의 원소\n);
for(i=1;i74;i++)
{
insert(list,i,rand()%100);
}
while(list)
{
printf(%d ,list-head-data);
list-head=list-head-next;
}
return 0;
}
제가 궁금한건 메인함수에서
list-head=p;
이후 함수들은 실행이 되지 않는다는 겁니다.
printf함수부터가 실행이 안되는거같습니다.
73개의 랜덤값을 집어넣어 출력을 하고싶은데 어디가 문제인건지 궁금합니다.
부탁드립니다.~
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |
2695010 | C++의 STL은 왜 굳이 템플릿화 시켜서 라이브러리를 만드나요? (초보수준의 질문..) (2) | 엘보어 | 2025-05-16 |
2694958 | 로직이 변한다는 것에 대해서 궁금합니다. | 튼동 | 2025-05-16 |
2694929 | 열혈강의 25-2 두번째 문제 질문 | 지우개 | 2025-05-15 |
2694900 | dequeue 에서 리턴값 프린트 방법알려주세요 오늘 12시까지 대화방에 있습니다 도와주세요 | 미투리 | 2025-05-15 |
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |