수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • 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

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

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

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