Good article.

My circular link list concept is tail-> next = head;

Code:
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>   // memset

#include "Link_List.h"

// -------------------------------------------------------
/*
   1. Insert Behind            // Done
   2. Insert In Front          // Done
   3. Random Insert Front-nth   // Done
   4. Remove Behind until zero or one only    // Done
   5. Remove In Front           // Done
   6. Random Remove -nth	   // Done
   7. Display                    // Done
   8. Length   Index            // Done
   9. Palindrome
   10. Full Reverse             // Circular Link List
   11. merge                    // Done  SortedMerge MergeSort
   12. Count a particular int
   13. Get_Node_At_Index        // Done
   14. Split List
   15. Remove Duplicates
   16. Swap
   17. Empty          // Done
   18. Calcualte number of node can malloc 
       from heap memory


Random cannot operate in head and tail

Double Link List
Double Circular Link List
Associate Link List
Skip List

Josephus problem

Searching
move-to-front heuristic = Once an elemnt found move to 
                          first node
Index

*/

 /* 
	Random must have a index to indicate the postion where
    almost same as array in order to achieve fast 
	processing
*/


// -------------------------------------------------------

// tail->next = head; Circular Link List

void draw();

// --------------------List Function----------------------

struct LList* list_allocate(struct LList *);
void list_deallocate(struct LList *);

void Initialize_List(struct LList *);

int LList_ValidateIsAlloc(struct LList *); 


struct LList* InsertBehind(struct LList *, struct node *);
struct LList* InsertFront(struct LList *, struct node*);
struct LList* RandomInsert(struct LList *, struct node*);
// Random Insert cannot insert at head and tail

struct LList* RemoveBehind(struct LList *);
struct LList* RemoveFront(struct LList *);
struct LList* RandomRemove(struct LList *);
// Random Remove cannot remove head and tail

struct LList* MergeList(struct LList *, struct LList *);


int get_Value_at_index(struct LList *);

int Validate_Index(struct LList *, int); 
int isEmpty(struct LList *);
int length_of_List(struct LList *);  


// --------------------Node Function----------------------

struct node* node_allocate(); 
void node_deallocate(struct node *); 


void Initialize_node(struct node *, int *); 
int node_validateIsAlloc(struct node *);   

void userInput(int *);
void display(const struct LList *);



// ------------------------------------------------------
int main(int argc, char *argv[]) // char **argv
{
	struct LList *myList = 0;
	struct LList *myListSecond = 0;
	struct node *node;

	int length = 0, result, number, *numberptr;

	numberptr = &number;
	
	draw();
	                  
	myList = list_allocate(myList); // Call by reference
	Initialize_List(myList);


// 1 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);//	InitializeCurrent(myList, node);
	myList = InsertBehind(myList, node);

// 2 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertBehind(myList, node);

// 3 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertBehind(myList, node);

// 4 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertBehind(myList, node);

// ----------------------------------------------------

// 2 List
	myListSecond = list_allocate(myList);
	Initialize_List(myListSecond);

// 1 node of 2 list
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myListSecond = InsertBehind(myListSecond, node);

    myList = MergeList(myList, myListSecond);

	// InsertFront
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertFront(myList, node);

	length = length_of_List(myList);
	display(myList);

	// Random Insert 
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = RandomInsert(myList, node);


	length = length_of_List(myList);
	display(myList);


	myList = RemoveBehind(myList);
	display(myList);


	result = get_Value_at_index(myList);

	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	InsertBehind(myList, node);

	display(myList);

	myList = RemoveFront(myList);

	display(myList);

	node_deallocate(node);
	list_deallocate(myList);
	
	return 0;
}

// ------------------------------------------------------
void draw()
{
	int loop;

	printf("\n\n\n\t\t");

	for (loop=0;loop<60;loop++)
	{
		printf("-");
	}
	
	printf("\n\n\t\t\t  Welcome to newly Link List Simulation Program");
	printf("\n\n\n\t\t");
	for (loop=0;loop<60;loop++)
	{
		printf("-");
	}
	printf("\n\n\n\n");
	
}
// -------------------------------------------------------
struct LList* list_allocate(struct LList *myList)
{
	int count = 1;

	do
	{
		myList = (struct LList *)malloc(sizeof(struct LList));
		assert(myList != NULL);
	 // Ptr must initialize No dangling ptr

		if (count == 2)
		{
			fprintf(stdout, "\n\t\t\tList Memory Allocation unsuccessful");
			exit(0);
		}
		count++;
		fflush(stdout);
	}while( LList_ValidateIsAlloc(myList) == 0 && count < 3);

	/* 
	   Continue to loop even though memory is exhausted 
	   for first time but not over second times because
	   this is unrealistic
	*/

	return myList;
}

// -------------------------------------------------------
void list_deallocate(struct LList *myList)
{
	if (myList != NULL)
	{
		free(myList);
		myList = NULL;
	}
	else
	{
		exit(0);
	}
}
// -------------------------------------------------------
void Initialize_List(struct LList *myList)
{
	if (LList_ValidateIsAlloc(myList) != 0) // Not NULL
	{
		myList->head = NULL;
		myList->tail = NULL;
	}
	else
	{
		exit(0);
	}
}
// -------------------------------------------------------
int LList_ValidateIsAlloc(struct LList *myList)
{
	assert(myList != NULL);

	// If allocation is successful, then return true
	if (myList != NULL)
	{
//		fprintf(stdout, "Memory Allocation successful");
		return 1;
	}// Three control structure
	else
	{
		fprintf(stdout, "Memory exhausted");
		return 0;
	}
}
// -------------------------------------------------------
struct node* node_allocate()
{
	struct node *node;
	int count = 1;

	do
	{
		node = (struct node *)malloc(sizeof(struct node));
		assert(node != 0);

		count++;

	}while(	node_validateIsAlloc(node) == 0 && count < 3);


	if (node != NULL)
	{
		return node;
	}
	else
	{
		exit(0);
	}
}

// -------------------------------------------------------
void node_deallocate(struct node *node)
{
	if (node != NULL)
	{
		free(node);
		node = NULL;
	}
	else
	{
		exit(0);
	}
}	
// -------------------------------------------------------
void Initialize_node(struct node *node, int * numberptr)
{
	node->next = NULL;
	
	node->value = *numberptr;
}
// -------------------------------------------------------
int node_validateIsAlloc(struct node *node)
{
	// If allocation is successful, then return true
	if (node != NULL)
	{
		fprintf(stdout, "\n\n\t\t\tNode Memory Allocation successful");
		return 1;
	}
	else
	{
		fprintf(stdout, "Memory exhausted");
		return 0;
	}
}
// ------------------------------------------------------
void userInput(int *numberptr)
{
	int number;
	
	fflush(stdin);
	printf("\n\n\t\t\t\tEnter a value : ");
	fflush(stdin);
	scanf("%d", &number);

	*numberptr = number;
}
// ------------------------------------------------------
struct LList* InsertBehind(struct LList *myList, struct node *node)
{	
	if (myList->head == NULL)
	{
		myList->head = node;
		myList->tail = node;	// Traversal ptr          

		myList->tail->next = NULL;
		node->previous = NULL;
		node->next = NULL;

		return myList;
	}
	else
	{
		while (myList->tail != NULL)
		{
			myList->tail->next = node;  // Previous node point to newly node
			node->previous = myList->tail;  // New node point to previous node   
			myList->tail = node;  // Traversal to new node	
			return myList;
		}
	}
}
// ------------------------------------------------------
struct LList* InsertFront(struct LList *myList, struct node *node)
{
	struct LList *tempHead;
	
	tempHead = (struct LList *)malloc(sizeof(struct LList *));
    assert(tempHead != 0);

	if ( LList_ValidateIsAlloc(tempHead) == 1 )
	{
		tempHead->head = myList->head;
		node->next = myList->head;
		node->previous = NULL;
		myList->head = node;
	}
	else
	{
		exit(0);
	}

	free(tempHead);

	return myList;
}
// ------------------------------------------------------
struct LList* RandomInsert(struct LList *myList, struct node *node)
{
	struct node *traversal_First;
	struct node *traversal_Second;
	struct node *dummy_one;
	struct node *dummy_two;

	// Position of node insert
	int index, length = 1; 

	traversal_First = myList->head;
	traversal_Second = myList->head;
	dummy_one = myList->head;
	dummy_two = myList->head;

	do
	{
		printf("\n\n\t\t\t\tEnter a index : ");
		scanf("%d", &index);  // Validate index no exceed length of list
	
		if ( Validate_Index(myList, index) == 1 )
		{
			length = 1;
			while (myList->tail != NULL && traversal_Second != NULL)
			{
				if (length == index)
				{
					traversal_First = traversal_First->previous;
					traversal_First->next = node;
					node->next = traversal_Second;
					node->previous = traversal_First;
					traversal_Second->previous = node;
					goto exit;
				}

				traversal_First = traversal_First->next;
				traversal_First->previous = dummy_one;
				dummy_one = traversal_First;

				traversal_Second = traversal_Second->next;
				traversal_Second->previous = dummy_two;
				dummy_two = traversal_Second;

				length++;
			}
			exit:
				return myList;
		}
	}while( Validate_Index(myList, index) == 0);
}
// -----------------------------------------------------
struct LList* RemoveBehind(struct LList *myList)
{
	struct node *traversal;
	struct node *dummy;

	int length = 1, real_length;
	int numberNode;

	real_length = length_of_List(myList);

	do
	{
		fprintf(stdout, "\n\n\t\t\tHow many removed node count from behind : ");
		scanf("%d", &numberNode);
	}while(numberNode > real_length || numberNode == 0);
	
	traversal = myList->head;

	length = 1;
	while (traversal->next != NULL)
	{
		traversal = traversal->next;
		length++;
	}

	// 1 2 3 4 5 
	numberNode = length - numberNode;

	do
	{
		dummy = myList->tail;
		myList->tail = myList->tail->previous;
		dummy->value = NULL;
		node_deallocate(dummy); // free what pointed by dummy  Error
		length--; 

	}while(length != numberNode);

	myList->tail->next = NULL;

	return myList;

}
// -----------------------------------------------------
struct LList* RemoveFront(struct LList *myList)
{
	struct node *removeHead, *removeTail, *traversal, *dummy;
	int numberNode, length, loop;

	removeHead = myList->head;
	removeTail = myList->head;
	traversal = myList->head;
	dummy = myList->head;


	do
	{
		fprintf(stdout, "\n\n\t\t\tHow many removed node count from in front : ");
		scanf("%d", &numberNode);

		length = length_of_List(myList);

	}while(numberNode > length || numberNode == length || numberNode == 0);


	myList->head = myList->head->next;
	for (loop=0;loop<numberNode - 1;loop++)
	{
		myList->head = myList->head->next;
		removeTail = removeTail->next;
	}

	removeTail->next = NULL;
	myList->head->previous = NULL;

	do
	{
		dummy = removeHead;
		removeHead = removeHead->next;
		traversal = traversal->next;

		dummy->value = NULL;
		node_deallocate(dummy);

	}while(traversal != NULL);

	return myList;
}
// ------------------------------------------------------
struct LList* RandomRemove(struct LList *myList)
{
	int indexOne, indexTwo; // To form a range

	fprintf(stdout, "Enter an index or range to remove : ");
	
	fprintf(stdout, "Enter first index : ");
	scanf("%d", &indexOne);

	fprintf(stdout, "Enter first index : ");
	scanf("%d", &indexTwo);

	return myList;
}
// ------------------------------------------------------
struct LList* MergeList(struct LList *first, struct LList *second)
{
	struct node *dummy;

	dummy = first->tail;

	first->tail->next = second->head;  // first list point to second list
	first->tail = first->tail->next;   // traverse to new tail after merge list
	first->tail->previous = dummy;    // tail node point back to second last node

	second = NULL;
	dummy = NULL;
	
	free(second);
	free(dummy);

	return first;
}
// ------------------------------------------------------
int get_Value_at_index(struct LList *myList)
{
	struct node *traversal;
	int length = 1, index, value, real_length;
	
	traversal = myList->head;

	do
	{
		fprintf(stdout, "\n\n\t\t\t\tEnter an index : ");
		scanf("%d", &index);

		real_length = length_of_List(myList);
	}while(index > real_length || index == 0);

	length = 1;
	do
	{
		if (index == length )
		{
			value = traversal->value;
			goto exit;
		}

		traversal = traversal->next;
		length++;
	}while (traversal->next != NULL && index != length);
	
	exit:
		value = traversal->value;
		fprintf(stdout, "\n\n\t\t\t\tValue at node %d of list is %d\n\n", index, value);
	return value;
}

// ------------------------------------------------------
int Validate_Index(struct LList *myList, int index)
{
	struct node *traversal;
	int length = 1;

	traversal = myList->head;

	length = 1;

	while (traversal->next != NULL)
	{
		traversal = traversal->next;
		length++;
	}

	if (index < length && index != 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
// ------------------------------------------------------
int isEmpty(struct LList *myList)
{
	if (myList->head == NULL)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
// ------------------------------------------------------
int length_of_List(struct LList *myList)
{
	struct node *traversal;
	int length = 1;
	
	traversal = myList->head;

	length = 1;
	while (traversal->next != NULL)
	{
		traversal = traversal->next;
		length++;
	}

	printf("\n\n\t\t\t\tLength of List is %d", length);
	

	return length;
}
// ------------------------------------------------------
void display(const struct LList * myList)
{
	printf("\n\n\n");

	struct node *traversal;
	int length;

	traversal = myList->head;

	length = 1;
	while(traversal != NULL)
	{
		printf("\t\t\t\tNode %d of List : %d\n", length, traversal->value);
		traversal = traversal->next;
		length++;
	}
	
}
// ------------------------------------------------------


[/QUOTE] 

[QUOTE]
#ifndef _LList_
#define _LList_

// Single Node
struct node
{
	int value;
	struct node *next;
	struct node *previous;
};


// Consists of many nodes
struct LList
{
	struct node *head;
	struct node *tail;
};

	
// Add index to struct

#endif

Any comment about my program ?

Thanks.

Last edited by shabbir; 31Jan2008 at 17:24.. Reason: Code block