연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다.
딥블랙
질문 제목 : 연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다. 질문 내용 :
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개의 랜덤값을 집어넣어 출력을 하고싶은데 어디가 문제인건지 궁금합니다.
부탁드립니다.~
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |