수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다.

딥블랙

2023.04.01


질문 제목 : 연결리스트 왜 이 다음줄이 실행되지 않는지 궁금합니다. 질문 내용 :
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개의 랜덤값을 집어넣어 출력을 하고싶은데 어디가 문제인건지 궁금합니다.
부탁드립니다.~

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
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
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com