c언어 초보인데 링크드 리스트 질문 드립니다.
Creator
질문 제목 :
이중 링크드 리스트 질문입니다.
데이터 값의 합계와 데이터값 거꾸로 출력하기
질문 내용 :
#include stdio.h
#include stdlib.h
#include memory.h
#include string.h
typedef int element;
typedef struct dlistnode
{
element data;
struct dlistnode *llink;
struct dlistnode *rlink;
}dlistnode;
//이중 연결 리스트를 초기화
void init(dlistnode *phead)
{
phead-llink = phead;
phead-rlink = phead;
}
//이중 연결 리스트의 노드를 출력
int display(dlistnode *phead)
{
dlistnode *p;
//int sum=0;
for(p=phead-rlink; p != phead; p = p-rlink)
{
printf(--- | %x | %d | %x | ----\n, p-llink, p-data, p-rlink);
}
printf(\n);
}
//노드 new_node를 노드 before의 오른쪽에 삽입한다.
int dinsert_node(dlistnode *before, dlistnode *new_node)
{
new_node-llink = before;
new_node-rlink = before-rlink;
before-rlink-llink=new_node;
before-rlink=new_node;
return new_node-data;
}
//노드 removed를 삭제한다.
void dremove_node(dlistnode *phead_node, dlistnode *removed)
{
if(removed == phead_node)
return;
removed-llink-rlink = removed-rlink;
removed-rlink-llink = removed-llink;
free(removed);
}
//이중 연결 리스트 테스트 프로그램
void main()
{
dlistnode head_node;
dlistnode *p[10];
int i;
init(&head_node);
for(i=0;i=9;i++)
{
p[i] = (dlistnode *)malloc(sizeof(dlistnode));
p[i]-data = i;
//헤드 노드의 오른쪽에 삽입
dinsert_node(&head_node, p[i]);
}
dremove_node(&head_node, p[4]);
display(&head_node);
}
제가 지금 하고 있는 이중 링크드 리스트 레포트 인데요
여기서 나온 데이터 값을 합계를 구해야 하는데 잘안되네요;;;
그리고 여기서 또 출력한 데이터 값을 거꾸로 출력 해야 합니다.
정말 모르겟네요 ;;;;; 답변 부탁 드릴게요;