본문 바로가기

C언어

듀얼 링크드 리스트(Dual linked list ) 구현

#include <stdio.h>
#include <String.h>

struct student{
	int number;

	struct student *next;
	struct student *previous;
};

int main (void){
	//s5-s2- s1- s4- s3 
	struct student s1 = {1,NULL};
	struct student s2 = {2,NULL};
	struct student s3 = {3,NULL};
	struct student s4 = {4,NULL};
	struct student s5 = {5,NULL};
	struct student *first = NULL;
	struct student *current = NULL;
	
	first = &s5;
	current = &s5;
	s5.previous = &s3;
	s5.next = &s2;
	
	s2.previous = &s5;
	s2.next = &s1;
	
	s1.previous = &s2;
	s1.next = &s4;
	
	s4.previous = &s1;
	s4.next = &s3;
	
	s3.previous = &s4;
	s3.next = &s5;
	
	while(current!=&s3){
		printf("%3d\n", current->number);
		current= current->next;
	}
	current = &s3;
	
	while(current!=&s5){
		printf("%3d\n", current->number);
		current = current->previous;
	}
	return 0;
	
	
}

자료구조 연습  

듀얼 링크드 리스트 구현

마지막은 처음으로 돌아가게끔.

처음의 이전노드는 마지막