#include <stdio.h>
#include <stdlib.h>


struct dlist_elem{
	int feild;
	struct dlist_elem *prev;
	struct dlist_elem *next;
};

void backward_print_dlist(int count, struct dlist_elem c);
void print_dlist(int count, struct dlist_elem c);

int
main()
{
	struct dlist_elem a1 = {10, NULL, NULL};
	struct dlist_elem a2 = {11, &a1, NULL};
	a1.next = &a2;

	struct dlist_elem a3 = {12, &a2, NULL};
	a2.next = &a3;

	struct dlist_elem a4 = {13, &a3, NULL};
	a3.next = &a4;

	struct dlist_elem a5 = {14, &a4, NULL};
	a4.next = &a5;

	struct dlist_elem a6 = {15, &a5, NULL};
	a5.next = &a6;

	backward_print_dlist(5, a5);
	print_dlist(5, a1);
}

void
print_dlist(int count, struct dlist_elem c)
{
	putchar('\n');
	struct dlist_elem *iter = &c;
	for(int i = 1; i <= count; i++)
	{
		printf("%d)Elem: %p\n\tField: %d\n\tNext: %p\n\tPrev: %p\n", i,iter, iter->feild, iter->next, iter->prev);
		iter = iter->next;
	}
}

void
backward_print_dlist(int count, struct dlist_elem c)
{
	putchar('\n');
	struct dlist_elem *iter = &c;
	for(int i = count; i > 0; i--)
	{
		printf("%d)Elem: %p\n\tField: %d\n\tNext: %p\n\tPrev: %p\n", i,iter, iter->feild, iter->next, iter->prev);
		iter = iter->prev;
	}
}
