//이중연결리스트 발생 자체만 설정함
#include<stdio.h>
#include<stdlib.h>
struct Node {
int value;
struct Node *PL;//왼쪽이동링크로 사용됨
struct Node *PR;//오른쪽이동링크로 사용됨
};
int main(void) {
struct Node *Head, *tail, *temp, *temp2, *wtf;
wtf=(struct Node *)malloc(sizeof(struct Node)); //동적 메모리 설정
wtf->value = 1;
wtf->PL = NULL;
wtf->PR = NULL;
Head = tail = temp = temp2 = wtf; // 위치 다 똑같음
for (int i = 2 ; i < 13; i++) { //데이터 삽입, 이동을 위한 for문
wtf=(struct Node *)malloc(sizeof(Node)); //동적 메모리 설정
wtf->value = i; //wtf가 가지는 주소값의 노드 value값에 i저장
wtf->PL = temp;
wtf->PR = NULL;
temp->PR = wtf;
temp = wtf;
}
temp = Head; //맨처음으로 이동
while (temp->PR) {//오른쪽으로 이동 출력
printf("%d ", temp->value);//값출력
temp = temp->PR;
}
while (temp->PL) {//왼쪽으로 이동 출력
printf("%d ", temp->value);//값출력
temp = temp->PL;
}
}
'Programming > C, C++' 카테고리의 다른 글
트리생성 (0) | 2013.05.21 |
---|---|
수식트리 (0) | 2013.05.21 |
Linkedlist (0) | 2012.12.26 |
Circular Queue (0) | 2012.12.21 |
Stack (0) | 2012.12.20 |
댓글