수다닷컴

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

c++ 리스트

차오름

2023.04.01


질문 제목 : 자료구조 리스트 부분하고 있다 더블포인터를 포인터 함수로 바꾸는건데..
막히네요..ㅠㅠ 어떻해 밑 요약에 있는거처럼 바꿀수잇을까용 ?void insert_node(listnode **phead, listnode *p, listnode *new_node) 함수를
void insert_node(listheadnode *phead, listnode *p, listnode *new_node)로 구현

typedef struct listheadnode {
struct listnode *headlink;
} listheadnode;

질문 내용 :

#include stdio.h
#include malloc.h
#include stdlib.h
#include limits.h
#define false 0
#define true 1
typedef int element;
typedef struct listnode {
element data;
struct listnode *link;
} listnode;
typedef struct {
listnode *head;
int length;
} listtype;
void insert_node(listnode **phead, listnode *p,
listnode *new_node)
{
if( *phead == null ){
new_node-link = null;
*phead = new_node;
}
else if( p == null ){
new_node-link = *phead;
*phead = new_node;
}
else {
new_node-link = p-link;
p-link = new_node;
}
}
void remove_node(listnode **phead, listnode *p, listnode *removed)
{
if( p == null )
*phead = (*phead)-link;
else
p-link = removed-link;
free(removed);
}
void init(listtype *list)
{
if( list == null ) return;
list-length = 0;
list-head = null;
}
listnode *get_node_at(listtype *list, int pos)
{
int i;
listnode *tmp_node = list-head;
if( pos 0 ) return null;
for (i=0; ipos; i++)
tmp_node = tmp_node-link;
return tmp_span c_node;
}
int get_length(listtype *list)
{
return list-length;
}
void error(char *message)
{
fprintf(stderr,%s\n,message);
exit(1);
}
void add(listtype *list, int position, element data)
{
listnode *p;
if ((position = 0) && (position = list-length)){
listnode*node= (listnode *)malloc(sizeof(listnode));
if( node == null ) error(메모리 할당에러);
node-data = data;
p = get_node_at(list, position-1);
insert_node(&(list-head), p, node);
list-length++;
}
}
void add_last(listtype *list, element data)
{
add(list, get_length(list), data);
}
void add_first(listtype *list, element data)
{
add(list, 0, data);
}
int is_empty(listtype *list)
{
if( list-head == null ) return 1;
else return 0;
}
void delete(listtype *list, int pos)
{
if (!is_empty(list) && (pos = 0) && (pos list-length)){
listnode *p = get_node_at(list, pos-1);
remove_node(&(list-head),p,(p!=null)?p-link:null);
list-length--;
}
}
element get_entry(listtype *list, int pos)
{
listnode *p;
if( pos = list-length ) error(위치 오류);
p = get_node_at(list, pos);
return p-data;
}
void clear(listtype *list)
{
int i;
for(i=0;ilist-length;i++)
delete(list, i);
}
void display(listtype *list)
{
int i;
listnode *node=list-head;
printf(( );
for(i=0;ilist-length;i++){
printf(%d ,node-data);
node = node-link;
}
printf( )\n);
}
int is_in_list(listtype *list, element item)
{
listnode *p;
p = list-head;
while( (p != null) ){
if( p-data == item )
break;
p = p-link;
}
if( p == null) return false;
else return true;
}
int main()
{
listtype list1;
init(&list1);
add(&list1, 0, 20);
add_last(&list1, 30);
add_first(&list1, 10);
add_last(&list1, 40);
display(&list1);
delete(&list1, 3);
display(&list1);
delete(&list1, 0);
display(&list1);
printf(%s\n, is_in_list(&list1, 20)==true ? 성공: 실패);
printf(%d\n, get_entry(&list1, 0));
}

신청하기





COMMENT

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

번호 제 목 글쓴이 날짜
2700426 인터넷 창 띄우는 질문이요 (1) 정훈 2025-07-04
2700400 원넓이를 계산이요 ㅜㅜ 천칭자리 2025-07-04
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
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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