연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다.
딥블랙
질문 제목 : 연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다. 질문 내용 :
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개의 랜덤값을 집어넣어 출력을 하고싶은데 어디가 문제인건지 궁금합니다.
부탁드립니다.~
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |
2694202 | 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) | 미나 | 2025-05-09 |
2694145 | 화면깜빡임을 없애고 싶은데요... (1) | 어서와 | 2025-05-08 |
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 |