GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #31  
Old 17-Feb-2008, 19:49
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Link List In C


What a tricky word in english workd ? I hate english.

CPP / C++ / C Code:
   // first try to empty the list
        // list_empty(pLList); // not yet implemented

 

What need to do in list_empty ?

CPP / C++ / C 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/RangeRemove -nth	   
   7. Display                    // Done
   8. Length   Index            // Done
   9. Palindrome
   10. Full Reverse             // Circular Link List  
       Remove first node, insert front
	   Remove second node, insert front

   11. merge                    // Done  SortedMerge MergeSort
   12. Count a particular int    // Done 
   13. Get_Node_At_Index        // Done
   14. Split List              // Done
   15. Remove Duplicates        
   16. Swap           // Done
   17. Empty          // Done
   18. Calcualte number of node can malloc 
       from heap memory
   19. Middle of Link List      // Done
   20. Compare two link list
   21.Interwine two link list   // Done


Random and swap cannot operate in head and tail

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

Floyd's Cycle-Finding Algorithm(The Tortoise and the Hare Algorithm)
Josephus problem

Searching
move-to-front heuristic = Once an elemnt found move to 
                          first node
Range search
Bi-Directional search
Linear search
Binary search

Sorting 
Library Sort
Merge Sort
Radix sort
Bucket Sort

Index
[url]http://www.codeuu.com/[/url]
[url]http://www.nist.gov/dads/[/url]
[url]http://www-igm.univ-mlv.fr/~lecroq/string/node31.html[/url]
[url]http://www.thescripts.com/forum/thread708138.html[/url]
*/

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

Memory Checking
these are some popular bounds-checking implementations
ccured [url]http://manju.cs.berkeley.edu/ccured/[/url]
cyclone [url]http://www.research.att.com/viewProject.cfm?prjID=67[/url]
splint [url]http://www.splint.org/[/url]
tinycc [url]http://fabrice.bellard.free.fr/tcc/[/url]
valgrind [url]http://valgrind.org/info/[/url]
rational purify [url]http://www-306.ibm.com/software/awdtools/purify/[/url]
electric fence [url]http://directory.fsf.org/project/ElectricFence/[/url]
parasoft insure++ [url]http://www.parasoft.com/jsp/products...product=Insure[/url]

more information: [url]http://www.doc.ic.ac.uk/teaching/pro...ewSuffield.pdf[/url]
*/

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

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

void draw();
int Main_menu();
int DLL_Function();
int ODCLL_Function();
int SL_Function();
int AL_Function();
int BST_Function();

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

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

void Initialize_List(struct LList *);

int LList_ValidateIsAlloc(struct LList *); 

int* Method_Interwine(int *);
struct LList* Interwine(struct LList *, struct LList *);


struct LList* SortedInsert(struct LList *, struct node *);
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* RemoveDuplicates(struct LList *);

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

struct LList* ReverseSwapNode(struct LList *, struct node *, struct node *);
struct LList* ReverseList(struct LList *);

void SplitList(struct LList *);
void AISplitList(struct LList *);
void UserSplitList(struct LList *);

int count_specific_value(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 *); 
int Middle_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 LList *myListThird = 0;

	struct node *node;

	int *ptr, numberList, choice, DLL_choice, ODCLL_choice, 
		middle, length = 0, result, number, *numberptr, resultNumber;
	
	// DLL Function Continue variable
	char DLL_continue = 'y', ODCLL_continue = 'y';

	numberptr = &number;
	
	draw();
/*
	choice = Main_menu();

	switch(choice)
	{
		case 1:
		{
			do
			{
				DLL_choice = DLL_Function();

				switch(DLL_choice)
				{
					case 1:
					{
						numberList = number_list();

						if (numberList == 1)
						{
							myList = list_allocate(myList);
						}
						else if (numberList == 2)
						{
							myList = myList;
							myListSecond = list_allocate(myListSecond);
							myListSecond = myListSecond;
						}
						else if (numberList == 3)
						{
							myListThird = list_allocate(myListThird);
						}
						break;
					}

					case 2:
					{
						node = node_allocate();
						break;
					}

					case 3:
					{
						userInput(numberptr);
						break;
					}

					case 4:
					{
						Initialize_node(node, numberptr);
						break;
					}

					case 5:
					{
						if (numberList == 1)
						{
							myList = InsertBehind(myList, node);
						}
						else if (numberList == 2)
						{
							myListSecond = InsertBehind(myListSecond, node);
						}
						else if (numberList == 3)
						{
							myListThird = InsertBehind(myListThird, node);
						}
						break;
					}

					case 6:
					{
						if (numberList == 1)
						{
							myList = InsertFront(myList, node);
						}
						else if (numberList == 2)
						{
							myListSecond = InsertFront(myListSecond, node);
						}
						else if (numberList == 3)
						{
							myListThird = InsertFront(myListThird, node);
						}
						break;
					}

					case 7:
					{
						if (numberList == 1)
						{
							myList = RandomInsert(myList, node);
						}
						else if (numberList == 2)
						{
							myListSecond = RandomInsert(myListSecond, node);
						}
						else if (numberList == 3)
						{
							myListThird = RandomInsert(myListThird, node);
						}
						break;

					}
					
					case 8:
					{
						if (numberList == 1)
						{
							myList = RemoveBehind(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = RemoveBehind(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = RemoveBehind(myListThird);
						}
						break;
					}

					case 9:
					{
						if (numberList == 1)
						{
							myList = RemoveFront(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = RemoveFront(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = RemoveFront(myListThird);
						}
						break;
					}
				
					case 10:
					{
						if (numberList == 1)
						{
							myList = RandomRemove(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = RandomRemove(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = RandomRemove(myListThird);
						}
						break;
					}

					case 11:
					{
						if (numberList == 1)
						{
							myList = RemoveDuplicates(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = RemoveDuplicates(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = RemoveDuplicates(myListThird);
						}
						break;
					}
				
					case 12:
					{
						myList = MergeList(myList, myListSecond);
						break;
					}

					case 13:
					{
						if (numberList == 1)
						{
							myList = SwapNode(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = SwapNode(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = SwapNode(myListThird);
						}
						break;
					}
				
					case 14:
					{
						if (numberList == 1)
						{
							SplitList(myList);
						}
						else if (numberList == 2)
						{
							SplitList(myListSecond);
						}
						else if (numberList == 3)
						{
							SplitList(myListThird);
						}					
						break;
					}

					case 15:
					{
						if (numberList == 1)
						{
							resultNumber = count_specific_value(myList);
						}
						else if (numberList == 2)
						{
							resultNumber = count_specific_value(myListSecond);
						}
						else if (numberList == 3)
						{
							resultNumber = count_specific_value(myListThird);
						}	
						break;
					}	
				
					case 16:
					{
						if (numberList == 1)
						{
							result = get_Value_at_index(myList);
						}
						else if (numberList == 2)
						{
							result = get_Value_at_index(myListSecond);
						}
						else if (numberList == 3)
						{
							result = get_Value_at_index(myListThird);
						}
						break;
					}

					case 17:
					{
						if (numberList == 1)
						{
							middle = Middle_of_List(myList);
						}
						else if (numberList == 2)
						{
							middle = Middle_of_List(myListSecond);
						}
						else if (numberList == 3)
						{
							middle = Middle_of_List(myListThird);
						}
						break;
					}
				
					case 18:
					{
						if (numberList == 1)
						{
							length = length_of_List(myList);
						}
						else if (numberList == 2)
						{
							length = length_of_List(myListSecond);
						}
						else if (numberList == 3)
						{
							length = length_of_List(myListThird);
						}
						break;
					}

					case 19:
					{	
						ptr = Method_Interwine(ptr);

						if ( *(ptr + 0) == 1 && *(ptr + 1) == 2)
						{
							myList = Interwine(myList, myListSecond);
						}
						else if ( *(ptr + 0) == 1 && *(ptr + 1) == 3)
						{
						    myList = Interwine(myList, myListThird);
						}
						else if ( *(ptr + 0) == 2 && *(ptr + 1) == 3)
						{
							  myList = Interwine(myListSecond, myListThird);
						}

						if (ptr != NULL)
						{
							free(ptr);
						}
						break;
					}
				
					case 20:
					{
						if (numberList == 1)
						{
							myList = ReverseList(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = ReverseList(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = ReverseList(myListThird);
						}
					}
					case 21:
					{
						if (numberList == 1)
						{
							display(myList);
						}
						else if (numberList == 2)
						{
							display(myListSecond);
						}
						else if (numberList == 3)
						{
							display(myListThird);
						}
						break;
					}
				
					default:
					{
						fprintf(stdout, "\n\n\t\t\t\t\tInvalid Choice");
						break;
					}
				}

				// fflush must put before scanf
				fflush(stdin);
				fprintf(stdout, "\n\n\t\t\t\t\tContinue : ");
				scanf("%c", &DLL_continue);
			
			}while(DLL_continue == 'y');
				
			break;
		}
		case 2:
		{
			do
			{
				ODCLL_choice = ODCLL_Function();

				switch(ODCLL_choice)
				{
					case 1:
					{
						numberList = number_list();

						if (numberList == 1)
						{
							myList = list_allocate(myList);
						}
						else if (numberList == 2)
						{
							myList = myList;
							myListSecond = list_allocate(myListSecond);
							myListSecond = myListSecond;
						}
						else if (numberList == 3)
						{
							myListThird = list_allocate(myListThird);
						}
						break;
					}

					case 2:
					{
						node = node_allocate();
						break;
					}

					case 3:
					{
						userInput(numberptr);
						break;
					}

					case 4:
					{
						Initialize_node(node, numberptr);
						break;
					}

					case 5:
					{
						if (numberList == 1)
						{
							myList = SortedInsert(myList, node);
						}
						else if (numberList == 2)
						{
							myListSecond = SortedInsert(myListSecond, node);
						}
						else if (numberList == 3)
						{
							myListThird = SortedInsert(myListThird, node);
						}
						break;
					}

					case 6:
					{
						if (numberList == 1)
						{
							myList = RemoveBehind(myList);
						}
						else if (numberList == 2)
						{
							myListSecond = RemoveBehind(myListSecond);
						}
						else if (numberList == 3)
						{
							myListThird = RemoveBehind(myListThird);
						}
						break;
					}

					case 7:
					{
						if (numberList == 1)
						{
							display(myList);
						}
						else if (numberList == 2)
						{
							display(myListSecond);
						}
						else if (numberList == 3)
						{
							display(myListThird);
						}
						break;
					}
					default:
					{
						fprintf(stdout, "\n\n\t\t\t\t\tInvalid Choice");
						break;
					}
				}
				// fflush must put before scanf
				fflush(stdin);
				fprintf(stdout, "\n\n\t\t\t\t\tContinue : ");
				scanf("%c", &DLL_continue);
			
			}while(ODCLL_continue == 'y');
			 break;
		}
		case 3:
		{
			break;
		}

		case 4:
		{
			break;
		}

		case 5:
		{
			break;
		}

		default:
		{
			break;
		}
	}

	if (myList != NULL)
	{
		free(myList);
	}

	if (myListSecond != NULL)
	{
		free(myListSecond);
	}

	if (myListThird != NULL)
	{
		free(myListThird);
	}
	
/*
	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);

//	myList = ReverseList(myList);
	display(myList);


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

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

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

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

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

// 10 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertBehind(myList, node);
/*
// 11 node
	node = node_allocate();
	userInput(numberptr);
	Initialize_node(node, numberptr);
	myList = InsertBehind(myList, node);

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

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

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

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

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

// ----------------------------------------------------
/*
// 2 List
	myListSecond = list_allocate(myList);
	Initialize_List(myListSecond);   // Finish

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

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

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

// 4 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);

	resultNumber = count_specific_value(myList);

	myList = RandomRemove(myList);
	display(myList);

	SplitList(myList);
	middle = Middle_of_List(myList);

	myList = SwapNode(myList);

	display(myList);
	display(myListSecond);

	myList = Interwine(myList, myListSecond);
*/
/*
	myList = RemoveDuplicates(myList);
	display(myList);
*/
	myList = list_allocate(myList);

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

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

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

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

	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");
	
}
// -------------------------------------------------------
int number_list()
{
	int number;


	fprintf(stdout, "\n\n\t\t\t\tWhich list to allocate : ");
	scanf("%d", &number);

	return number;
}
// -------------------------------------------------------
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
	*/

	Initialize_List(myList); // Initilize Link List

	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)
{
	if (node != NULL)
	{
		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\t\tEnter a value : ");
	fflush(stdin);
	scanf("%d", &number);

	*numberptr = number;
}
// ------------------------------------------------------
struct LList* SortedInsert(struct LList *myList, struct node *node)
{
	struct node *traversal, *traversal_before;
	int length;

	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_before = myList->head;

		if (myList->head == NULL)
		{
			myList->head = node;
			myList->tail = node;	// Traversal ptr          

			// Circular
	//		myList->tail->next = myList->head;
		}
		else
		{
			length = 1;
			while(traversal->next != NULL && traversal->value < node->value)
			{
				traversal = traversal->next;
				traversal_before = traversal_before->next;
			}
				if (traversal->value < node->value)
				{
					if (traversal->next != NULL)
					{
						node->next = traversal->next;
					}
					traversal->next = node;
					node->previous = traversal;
				}
				else
				{
					if (traversal_before->previous != NULL)
					{
						traversal_before = traversal_before->previous;
						
						traversal_before->next = node;
						node->previous = traversal_before;

						node->next = traversal;
						traversal->previous = node;
					}
					else
					{
						traversal_before->next = node;
						node->previous = traversal_before;

						node->next = traversal;
						traversal->previous = node;
					}
				}
		}
	}
	else
	{
		exit(0);
	}

	return myList;
}
// ------------------------------------------------------
struct LList* InsertBehind(struct LList *myList, struct node *node)
{	
	if (myList != NULL)
	{
		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;
			}
		}
	}
	else
	{
		return myList;
	}

	return myList;
}
// ------------------------------------------------------
struct LList* InsertFront(struct LList *myList, struct node *node)
{
	struct LList *tempHead;
	
	if (myList != NULL)
	{
		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);
	}
	else
	{
		return myList;
	}

	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; 

	
	if (myList != NULL)
	{
		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 to random insert : ");
			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);
	}
	else
	{
		return myList;
	}
}
// -----------------------------------------------------
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);

	if (myList != NULL)
	{
		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;
	}
	else
	{
		return myList;
	}
	return myList;

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


	if (myList != NULL)
	{
		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);
	}
	else
	{
		return myList;
	}

	return myList;
}
// ------------------------------------------------------
struct LList* RandomRemove(struct LList *myList)
{
	struct node *traversal, *traversal_first, *middle, *middle_two, *freeNode;

	int indexOne, indexTwo, length, remove_length; // To form a range


	
	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_first = myList->head;
		middle = myList->head;
		middle_two = myList->head;
	
		length = length_of_List(myList);
		fprintf(stdout, "\n\n\t\t\tEnter an index or range to remove : ");
	
		do
		{
			fprintf(stdout, "\n\n\t\t\t\tEnter random remove first index : ");
			scanf("%d", &indexOne);

			fprintf(stdout, "\n\n\t\t\t\tEnter random remove second index : ");
			scanf("%d", &indexTwo);
		}while(indexOne > length || indexTwo > length || indexOne == 0);

		// Range Remove
		if (indexTwo != 0)
		{
			length = 1;
			while(traversal_first->next != NULL)
			{
				if (indexTwo >= length)
				{
					traversal_first = traversal_first->next;
					middle_two = middle_two->next;
					length++;
				}

				if (length <= indexOne)
				{
					traversal = traversal->next;	
					middle = middle->next;
				}

		/*		if (length <= indexTwo)
				{
					middle_two = middle_two->next;
				}*/
	
				if (indexOne == length)
				{
					traversal = traversal->previous;
					traversal->next = NULL;
				}

				if (length - 1 == indexTwo)
				{
					//middle_two = middle_two->previous;
					//middle_two->next = NULL;
		
					traversal_first->previous = NULL;
					remove_length = (indexTwo - indexOne) + 1;

					length = 1;
					while(length <= remove_length)
					{
						freeNode = middle;
						if (middle->next != NULL)
						{
							middle = middle->next;
						}
						middle->previous = NULL;

						freeNode->value = 0;
						freeNode->previous = NULL;
						freeNode->next = NULL;
						node_deallocate(freeNode);
						length++;
				
					}

					traversal->next = traversal_first;
		
					traversal_first->previous = traversal;
					goto exit;
				}
			
			}
		}
		// Single Random Remove
		else
		{
			length = 1;
			while(traversal != NULL)
			{
				if (indexOne == length)
				{
					traversal = traversal->previous;
					traversal_first = traversal_first->next;

					traversal->next = traversal_first;
					traversal_first->previous = traversal;
				
					middle->value = NULL;
					node_deallocate(middle);
					goto exit;
				}
				traversal = traversal->next;
				traversal_first = traversal_first->next;
				middle = middle->next;
				length++;
			}
		}
	}
	else
	{
		return myList;
	}
exit:
	return myList;
}
// ------------------------------------------------------
struct LList* RemoveDuplicates(struct LList *myList)
{
	struct node *traversal, *traversal_before, *traversal_after;
	int *numberptr, temp_length = 1, length = 1, loop, bound;

	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_before = myList->head;
		traversal_after = myList->head;
		length = length_of_List(myList);
		bound = length;

		numberptr = (int *) malloc (sizeof(int) * length);
		assert(numberptr != 0);

		printf("\n\n");
		length = 1;
		do 
		{
			if (length <= bound)  // bound checking
			{
				*(numberptr + length - 1) = traversal->value; 
				printf("%d\n", *(numberptr + length -1) );
			}
			traversal = traversal->next;
			length++;

		}while(traversal != NULL);

		traversal = myList->head; 
		length = length_of_List(myList);

		// Compare and to remove duplicates
		temp_length = 1;
		do 
		{
			loop = 1;
			while(loop <= length) // 0 - 6
			{ 
				if (loop == length && length == 1 || loop == 1)
				{	
					if (traversal_before != NULL && traversal_after != NULL)
					{
						traversal_before = traversal_before->next;
						traversal_after = traversal_after->next;
					}
				}

				if ( traversal->value == traversal_before->value )
				{	
					traversal_before = traversal_before->previous;
					
					if (traversal_after != NULL)
					{
						traversal_after = traversal_after->next;
					}
					else
					{
						traversal_before->next = NULL;
//						traversal_after->next = NULL;
					}
//					traversal->previous = NULL;
//					traversal->next = NULL;

					// bug
					traversal_before->next = traversal_after; 
					
					if (traversal_after != NULL)
					{
						traversal_after->previous = traversal_before;
					}
//					node_deallocate(traversal);

				}
				if (traversal_before != NULL && traversal_after != NULL)
				{
					traversal_before = traversal_before->next;
					traversal_after = traversal_after->next;
				}
				myList = myList;
				loop++;
			}
			if (traversal->next != NULL)
			{
				traversal = traversal->next;
			}
			temp_length++;

		}while(traversal->next != NULL);  // 1 - 7 
	}
	else
	{
		return myList;
	}

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

	
	if (first != NULL && second != NULL)
	{
		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);
	}
	else
	{
		return first;
	}

	return first;
}
// ------------------------------------------------------
int* Method_Interwine(int *ptr)
{
	int numberFirstList, numberSecondList;

	ptr = (int *)malloc(sizeof(int) * 2);
	assert (ptr != NULL);
//	fflush(stdin);

	if (ptr != NULL)
	{
		printf("\n\n\t\t\t\t\tEnter First List : ");
		scanf("%d", &numberFirstList);
	
		printf("numberFirstList is %d", numberFirstList);
//		fflush(stdin);
		printf("\n\t\t\t\t\tEnter Second List : ");
		scanf("%d", &numberSecondList);

		if (numberFirstList != 0 && numberSecondList != 0)
		{
			*(ptr + 0) = numberFirstList;
			*(ptr + 1) = numberSecondList;
		}
	}
	else
	{
//		exit(0);
	}

	// To ensure the function definition malloc memory 
	// is appear in main

	fprintf(stdout, "%d\n\n%d", *(ptr + 0) , *(ptr + 1) );
	return ptr;
	
}

// ------------------------------------------------------
struct LList* Interwine(struct LList *myList, struct LList *myListSecond)
{
	struct node *traversal_first, *traversal_second;
	// Traversal for first list after current
	struct node *traversal_next;

	int length, first_length, second_length;

	/*  
		Interwine example  
		
		First List - 6,3,8,1,44
		Second List - 9,-3,10,100,54

		Result - 6,9,3,-3,8,10,1,100,44,54
    */
	
	first_length = length_of_List(myList);
	second_length = length_of_List(myListSecond);

	if (first_length >= 2 && second_length >= 2)
	{
		if (myList != NULL && myListSecond != NULL)
		{
			traversal_first = myList->head;
			traversal_second = myListSecond->head;
			// Point at second node of first list 
			traversal_next = myList->head->next;

			length = 1;
			do 
			{
				// Algorithm 
			
				// Pointing
				if (myListSecond->head->next != NULL)
				{
					myListSecond->head = myListSecond->head->next;
				}

		//		// bug
				if (length != 1 && length != second_length)
				{
					traversal_second = myListSecond->head->previous;
				}

				if (length == second_length)
				{
					traversal_second = myListSecond->head;
				}

				traversal_first->next = traversal_second;
				traversal_second->previous = traversal_first;
			
				traversal_second->next = traversal_next;
			
// bug	
				if (traversal_next != NULL)
				{
					traversal_next->previous = traversal_second;
				}

				if (traversal_first->next != NULL && traversal_first->next->next)
				{
					traversal_first = traversal_first->next->next;
				}

				if (myList->tail != NULL && traversal_next != NULL)
				{
					traversal_next = traversal_next->next;
				}

				if (myList->tail->next != NULL)
				{
					myList->tail = myList->tail->next;
				}

				length++;

				if (length == second_length + 1)
				{
//					myListSecond->head->next = NULL;
//					myListSecond->tail->previous = NULL;
					goto exit;
				}

			}while(myList->tail != NULL);
		}
		else
		{
			exit(0);
		}
	}

exit:
	display(myList);
//	list_deallocate(myListSecond);

	return myList;
}
// ------------------------------------------------------
void SplitList(struct LList *myList)
{
	int choice; 

	printf("\n\n\t\t\t\t   1. AI Split\n\t\t\t\t   2. User Split");
	fprintf(stdout, "\n\n\t\t\t\t Enter a Choice : ");
	scanf("%d", &choice);

	switch(choice)
	{
		case 1:
			{
				if (myList != NULL)
				{
					AISplitList(myList);
				}
				break;
			}
		case 2:
			{
				if (myList != NULL)
				{
					UserSplitList(myList);
				}
				break;
			}
		default:
			{
				fprintf(stdout, "Invalid choice");
			}
	}
}
// ------------------------------------------------------
void AISplitList(struct LList *myList)
{
	struct LList *firstList, *secondList, *thirdList, 
		*fourthList, *fifthList;

	// Temp Tail 
	struct node *traversal, *traversal_second, 
		*traversal_third, *traversal_fourth, 
		*traversal_fifth;

	// temp_length indicate location to split
	// real_length indicate real length
	// user_length indicate length to split
	int temp_remainder, user_length, temp_length = 1,  
		numberSplit, real_length, count_list = 1;
	float remainder ;

	traversal = myList->head;
	traversal_second = myList->head;
	traversal_third = myList->head;
	traversal_fourth = myList->head;
	traversal_fifth = myList->head;

	firstList = (struct LList *)malloc(sizeof(struct LList));
	assert (firstList != 0);

	secondList = (struct LList *)malloc(sizeof(struct LList));
	assert (secondList != 0);

	thirdList = (struct LList *)malloc(sizeof(struct LList));
	assert (thirdList != 0);

	fourthList = (struct LList *)malloc(sizeof(struct LList));
	assert (fourthList != 0);

	fifthList = (struct LList *)malloc(sizeof(struct LList));
	assert (fifthList != 0);


	real_length = length_of_List(myList);

	/* 
	   AI
	   This may seems unrealistic in real world database
	   application
    */

	if (real_length <= 10)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 2 List");
	}
	else if (real_length > 10 && real_length <= 20)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 2 and 4 List");
	}
	else if (real_length > 20 && real_length <= 50)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 5 List");
	}
	else
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split cannot be achieve");
	}
	
	do
	{
		fprintf(stdout, "\n\n\t\t\t\tHow many list to split : ");
		scanf("%d", &numberSplit);
	}while(numberSplit > real_length && numberSplit == real_length || numberSplit == 0 && numberSplit < 6);
	// Make it as balanced as possible How to split perfect split and not balance split 2-3,3-4(2-5),4-5
	
	user_length = real_length;

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

/*
                                                      UL 
                                                NS    __
                                Remainder < 2   _____|      
                                               |     |__
                   Got         ________________|
				 Remainder    |                |      __
				              |                |_____|
                ______________|                      |__
               |              |
			   |              |
			   |              |________________
			   |              
_______________|                Remainder >= 2
               |                   
               |               ________ NS ________ UL
			   |              |
			   |              |
			   |______________|
	                          |
					 No       |
				  Remainder   |________ NS ________ UL
	
*/	
	
	if (real_length % numberSplit != 0)
	{
		// User length is length of sub list
		// To check remainder
		if (real_length % numberSplit < 2)
		{
			// Remainder 1/2 = 0.5 
		
			temp_remainder = user_length % numberSplit;
			remainder = (float)temp_remainder;
			
			// Handle remainder = 1
			remainder = remainder / numberSplit;
			user_length = user_length / numberSplit;

			if (remainder >= 0.5) 
			{
				user_length = user_length + 1;

				if (numberSplit == 2)
				{
					// 5/2 
					if (user_length == 3)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}

									goto loop;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										goto exit;
									}
									goto loop;
								}
							
							}
							
							loop:
								temp_length++;
							
								if (temp_length > user_length && count_list != 3)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}

					// 7/2
					if (user_length == 4)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}
									goto loop1;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										goto exit;
									}
									goto loop1;
								}
							}
							loop1:
								temp_length++;
							
								if (temp_length > user_length && count_list != 3)
								{
									temp_length = 1;
									count_list++;
								}
						}

					}

					// 9/2
					if (user_length == 5)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}
									goto loop2;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										goto exit;
									}

									goto loop2;
								}
								loop2:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
				}

				// 14/4 
				if (numberSplit == 4)
				{
					if (user_length == 4)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop9;
								}
								loop9:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
					 
				}
			}
          // Remainder not equal to 0.5
		  // Handle remainder = 2
			else
			{	
				if (numberSplit == 3)
				{
					// 7/3 
					if (user_length == 2)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}
									goto loop3;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop3;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop3;
								}
								loop3:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
	
					// 13/3
					if (user_length == 4)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}
									goto loop4;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop4;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop4;
								}
								loop4:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
							
					}

					// 16/3
					if (user_length == 5)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									goto loop5;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop5;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4 || temp_length == 5)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 6)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop5;
								}
								loop5:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}
				}

				if (numberSplit == 4)
				{
					// 9/4
					if (user_length == 2)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{

								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									
									if (temp_length == 2)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop6;
								}
								loop6:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}

					// 13/4
					if (user_length == 3)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;

									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop7;
								}
								loop7:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 4)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									goto loop26;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop26;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop26;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop26;
								}
								loop26:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}

					if (user_length == 5)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop27;
								}
								loop27:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}		
							}
						}
					}
				}

				if (numberSplit == 5)
				{
					if (user_length == 2)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second; 
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop28;
								}
								loop28:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 3)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop29;
								}
								loop29:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 4)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										firstList->head = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									goto loop30;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										thirdList->head = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop30;
								}
								loop30:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 5)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop31;
								}
								loop31:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}
				}
			}
		}
     // ---------------------------------- 
		// remainder equal or over 2
		else
		{
			user_length = user_length / numberSplit;
			user_length = user_length + 1;

			if (numberSplit == 2)
			{
				if (user_length == 3)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 3)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}
								goto loop32;
							}
	
							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 3)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop32;
							}
							loop32:
								temp_length++;
							
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}	
						}
					}
				}

				if (user_length == 4)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}

								goto loop33;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->next = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop33;
							}
							loop33:
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}

								goto loop34;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->next = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop34;
							}
							loop34:
								temp_length++;
								
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}

			if (numberSplit == 3)
			{
				if (user_length == 2)
				{
					while(traversal_third != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}
								goto loop35;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									secondList->tail = traversal_second; 
									traversal_third = traversal_third->next;
								}
								goto loop35;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									thirdList->tail = traversal_third;
									goto exit;
								}
								goto loop35;
							}
							loop35:
								temp_length++;
								
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 3)
				{
				}

				if (user_length == 4)
				{
				}

				if (user_length == 5)
				{
				}
			}

			if (numberSplit == 4)
			{
				if (user_length == 2)
				{
				}

				if (user_length == 3)
				{
				}

				// 15/4
				if (user_length == 4)
				{
					while(traversal_fourth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2)
								{
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 3)
								{
									fourthList->tail = traversal_fourth;
									goto exit;
								}
								goto loop8;
							}
							loop8:
								temp_length++;
							
								if (temp_length > user_length && count_list != 4)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_fourth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal->next;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									fourthList->tail = traversal_fourth;
									goto exit;
								}
								goto loop36;
							}
							loop36:
								temp_length++;
							
								if (temp_length > user_length && count_list != 4)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}

			if (numberSplit == 5)
			{
				if (user_length == 2)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									firstList->head = traversal ;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop37;
							}
							loop37:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 3)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop38;
							}
							loop38:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}	
						}
					}
				}

				if (user_length == 4)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									fifthList->tail =traversal_fifth;
									goto exit;
								}
								goto loop39;
							}
							loop39:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->previous = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop40;
							}
							loop40:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}
		}
	}
// --------------------------- 
// No remainder
	else
	{
		user_length = real_length / numberSplit;

		if (numberSplit == 2)
		{
			if (user_length == 2)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop10;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop10;
						}

						loop10:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop11;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop11;
						}
						loop11:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}
							
							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 4)
							{
								firstList->head = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop12;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}
							
							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 4)
							{
								secondList->head = traversal_second;
								goto exit;
							}
							goto loop12;
						}
					}
					loop12:
						if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
				}
			}

			if (user_length == 5)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop13;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop13;
						}
						loop13:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 3)
		{
			if (user_length == 2)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop14;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop14;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head  = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop14;
						}
						loop14:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}	
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop15;
						}
		
						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop15;
						}	

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop15;
						}
						loop15:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}	
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop16;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop16;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop16;
						}
						loop16:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop17;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop17;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop17;
						}
						loop17:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 4)
		{
			if (user_length == 2)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop18;
						}
						loop18:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			// 12/3 
			if (user_length == 3)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop19;
						}
						loop19:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			// 16/4
			if (user_length == 4)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop20;
						}
						loop20:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop21;
						}
						loop21:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 5)
		{
			if (user_length == 2)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal->next;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop22;
						}
						loop22:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop23;
						}
						loop23:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop24;
						}
						loop24:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop25;
						}
						loop25:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}
	}


	// ------------------ Display --------------------

exit: 
	if (traversal == firstList->tail)
	{
		traversal = firstList->head;

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

	if (traversal_second == secondList->tail)
	{
		printf("\n\n\t\t\t\t   Second List\n\n");
		traversal_second = secondList->head;

		temp_length = 1;
		while(secondList != NULL && traversal_second != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_second->value);
			traversal_second = traversal_second->next;
			temp_length++;
		}
	}

	if (traversal_third == thirdList->tail)
	{
		printf("\n\n\t\t\t\t   Third List\n\n");
		traversal_third = thirdList->head;

		temp_length = 1;
		while(thirdList != NULL && traversal_third != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_third->value);
			traversal_third = traversal_third->next;
			temp_length++;
		}
	}

	if (traversal_fourth == fourthList->tail)
	{
		printf("\n\n\t\t\t\t   Fourth List\n\n");
		traversal_fourth = fourthList->head;

		temp_length = 1;
		while(fourthList != NULL && traversal_fourth != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_fourth->value);
			traversal_fourth = traversal_fourth->next;
			temp_length++;
		}
	}

	if (traversal_fifth == fifthList->tail)
	{
		printf("\n\n\t\t\t\t   Fifth List\n\n");
		traversal_fifth = fifthList->head;
			
		temp_length = 1;
		while(fifthList != NULL && traversal_fifth != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_fifth->value);
			traversal_fifth = traversal_fifth->next;
			temp_length++;
		}
	}

	// ----------------------Free--------------------

	if (firstList != NULL)  
	{
		free(firstList);
	}

	if(secondList != NULL)
	{
		free(secondList);
	}

	if (thirdList != NULL) 
	{
		free(thirdList);

	}
	if(fourthList != NULL)
	{
		free(fourthList);
	}

	if (fifthList != NULL)
	{
		free(fifthList);
	}
}
// ------------------------------------------------------
void UserSplitList(struct LList *myList)
{
	struct node *traversal;
	struct node *firstTail, *secondTail, *thirdTail,
		*fourthTail, *fifthTail;

	struct LList *firstList, *secondList, *thirdList,
		*fourthList, *fifthList;

	int real_length, numberSplit, count_list,
		listOneIndexOne, listOneIndexTwo, 
		listTwoIndexOne, listTwoIndexTwo,
		listThreeIndexOne, listThreeIndexTwo,
		listFourIndexOne, listFourIndexTwo,
		listFiveIndexOne, listFiveIndexTwo,
		length;
	// To indicate range to split by user

	traversal = myList->head;

	thirdList = NULL;
	fourthList = NULL;
	fifthList = NULL;

	if (myList != NULL)
	{
		real_length = length_of_List(myList);
		// To get numberSplit from user
		do
		{
			fprintf(stdout, "\n\n\t\t\t\tHow many List to split : ");
			scanf("%d", &numberSplit);
		}while(numberSplit > 6 || numberSplit == 0);

		// To get index from user
		count_list = 1;
		do
		{
			if (count_list == 1)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\t\tList One Index One : ");
					scanf("%d", &listOneIndexOne);
					fprintf(stdout, "\n\t\t\t\tList One Index Two : ");
					scanf("%d", &listOneIndexTwo);
				}while(listOneIndexOne != 1);

				do
				{
					firstList = (struct LList *)malloc(sizeof(struct LList));
					assert(firstList != 0);
				}while(firstList == NULL);
			}

			if (count_list == 2)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\t\tList Two Index One : ");
					scanf("%d", &listTwoIndexOne);
					fprintf(stdout, "\n\t\t\t\tList Two Index Two : ");
					scanf("%d", &listTwoIndexTwo);
				}while(listTwoIndexOne == listOneIndexTwo || listTwoIndexOne - listOneIndexTwo > 1);
				
				do
				{
					secondList = (struct LList *)malloc(sizeof(struct LList));
					assert(secondList != 0);
				}while(secondList == NULL);
			}

			if (count_list == 3)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\t\tList Three Index One : ");
					scanf("%d", &listThreeIndexOne);
					fprintf(stdout, "\n\t\t\t\tList Three Index Two : ");
					scanf("%d", &listThreeIndexTwo);
				}while(listThreeIndexOne == listTwoIndexTwo || listThreeIndexOne - listTwoIndexTwo > 1);
			
				do
				{
					thirdList = (struct LList *)malloc(sizeof(struct LList));
					assert(thirdList != 0);
				}while(thirdList == NULL);
			}

			if (count_list == 4)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\t\tList Four Index One : ");
					scanf("%d", &listFourIndexOne);
					fprintf(stdout, "\n\t\t\t\tList Four Index Two : ");
					scanf("%d", &listFourIndexTwo);
				}while(listFourIndexOne == listThreeIndexTwo || listFourIndexOne - listThreeIndexTwo > 1);
			
				do
				{
					fourthList = (struct LList *)malloc(sizeof(struct LList));
					assert(fourthList != 0);
				}while(fourthList == NULL);
			}

			if (count_list == 5)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\t\tList Five Index One : ");
					scanf("%d", &listFiveIndexOne);
					fprintf(stdout, "\n\t\t\t\tList Five Index Two : ");
					scanf("%d", &listFiveIndexTwo);
				}while(listFiveIndexOne == listFourIndexTwo || listFiveIndexOne - listFourIndexTwo > 1);
			
				do
				{
					fifthList = (struct LList *)malloc(sizeof(struct LList));
					assert(fifthList != 0);
				}while(fifthList == NULL);
			}
			count_list++;
		}while(count_list <= numberSplit);

		// To split the list specified by user
		length = 1;
		do
		{
			// List 1
			if (length == 1 && listOneIndexOne == length)
			{
				firstList->head = traversal;
			}

			if (listOneIndexTwo == length)
			{
				firstList->tail = traversal;
			}

			// List 2
			if (listTwoIndexOne == length)
			{
				firstList->tail->next = NULL;
				secondList->head = traversal;
				secondList->head->previous = NULL;
			}

			if (listTwoIndexTwo == length)
			{
				secondList->tail = traversal;
			}

			// List 3
			if (listThreeIndexOne != NULL)
			{
				if (listThreeIndexOne == length)
				{
					secondList->tail->next = NULL;
					thirdList->head = traversal;
					thirdList->head->previous = NULL;
				}
			}

			if (listThreeIndexTwo != NULL)
			{
				if (listThreeIndexTwo == length)
				{
					thirdList->tail = traversal;
				}
			}

			// List 4
			if (listFourIndexOne != NULL)
			{
				if (listFourIndexOne == length)
				{
					thirdList->tail->next = NULL;
					fourthList->head = traversal;
					fourthList->head->previous = NULL;
				}
			}

			if (listFourIndexTwo != NULL)
			{
				if (listFourIndexTwo == length)
				{
					fourthList->tail = traversal;
				}
			}

			// List 5
			if (listFiveIndexOne != NULL)
			{
				if (listFiveIndexOne == length)
				{
					fourthList->tail->next = NULL;
					fifthList->head = traversal;
					fifthList->head->previous = NULL;
				}
			}
			
			if (listFiveIndexTwo != NULL)
			{
				if (listFiveIndexTwo == length)
				{
					fifthList->tail = traversal;
				}
			}

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

		// ---------------------Display-----------------

		// List 1
		if (firstList->head != NULL && firstList->tail != NULL)
		{
			firstTail = firstList->head;

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

		// List 2
		if (secondList != NULL)
		{
			secondTail = secondList->head;

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

		// List 3
		if (thirdList != NULL)
		{
			thirdTail = thirdList->head;

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

		// List 4
		if (fourthList != NULL)
		{
			fourthTail = fourthList->head;

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

		// List 5
		if (fifthList != NULL )
		{
			fifthTail = fifthList->head;

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

		// ----------------------Free-------------------

		if (firstList != NULL)  
		{
			free(firstList);
		}

		if(secondList != NULL)
		{
			free(secondList);
		}

		if (thirdList != NULL) 
		{
			free(thirdList);
		}

		if(fourthList != NULL)
		{
			free(fourthList);
		}

		if (fifthList != NULL)
		{
			free(fifthList);
		}

	}
	else
	{
		exit(0);
	}

}
// ------------------------------------------------------
struct LList* SwapNode(struct LList *myList)
{
	struct node *indexFirstNodeBefore, 
		*indexFirstNodeMiddle, *indexFirstNodeAfter,
		*indexSecondNodeBefore, *indexSecondNodeMiddle,
		*indexSecondNodeAfter, *temp_head, *temp_tail, *dummy, *dummy_tail;

	int indexFirstNode, indexSecondNode, index = 1,
		substract, length;
	char flag = 'y';

	if (myList != NULL)
	{
		indexFirstNodeBefore = myList->head;
		indexFirstNodeMiddle = myList->head; 
		indexFirstNodeAfter = myList->head;
		indexSecondNodeBefore = myList->head;
		indexSecondNodeMiddle = myList->head;
		indexSecondNodeAfter = myList->head;

		temp_head = myList->tail;
		temp_tail = myList->head;

		length = length_of_List(myList);

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

			substract = indexSecondNode - indexFirstNode;
		}while(substract < 3 && length > 2);
			
		do 
		{
			// Swap Head and Tail Algorithm

			if (indexFirstNode == 1 && index == indexFirstNode)
			{
				dummy = myList->head->next;
				dummy->previous = NULL;

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

				temp_head->previous = NULL;
				temp_tail->next = NULL;

				myList->head = temp_head;
				myList->head->next = dummy;
				dummy->previous = myList->head;

				myList->tail = temp_tail;
				myList->tail->next = NULL;
				myList->tail->previous = dummy_tail;
				dummy_tail->next = myList->tail;

				flag = 'n';
			}

			if (index == indexFirstNode && indexSecondNode != length)
			{
				indexFirstNodeBefore = indexFirstNodeBefore->previous;
				indexFirstNodeAfter = indexFirstNodeAfter->next;
			}

			if (index == indexSecondNode)
			{
				indexSecondNodeBefore = indexSecondNodeBefore->previous;
				indexSecondNodeAfter = indexSecondNodeAfter->next;

				// Starting swap algorithm 
				indexFirstNodeBefore->next = indexSecondNodeMiddle;
				indexSecondNodeMiddle->previous = indexFirstNodeBefore;
				
				indexSecondNodeAfter->previous = NULL;

				indexSecondNodeMiddle->next = indexFirstNodeAfter;
				indexFirstNodeAfter->previous = indexSecondNodeMiddle;

				indexSecondNodeBefore->next = indexFirstNodeMiddle;
				indexFirstNodeMiddle->previous = indexSecondNodeBefore;
				indexFirstNodeMiddle->next = indexSecondNodeAfter;

				flag = 'n';
			}

			// Traversal throught the list
			if (index != indexFirstNode && index < indexFirstNode)
			{
				indexFirstNodeBefore = indexFirstNodeBefore->next;
				indexFirstNodeMiddle = indexFirstNodeMiddle->next;
				indexFirstNodeAfter = indexFirstNodeAfter->next;
			}
			
			if (index != indexSecondNode && index < indexSecondNode)
			{
				indexSecondNodeBefore = indexSecondNodeBefore->next;
				indexSecondNodeMiddle = indexSecondNodeMiddle->next;
				indexSecondNodeAfter = indexSecondNodeAfter->next;
			}
			index++;
		}while(flag == 'y');
	}
	else
	{
		return myList;
	}

	fprintf(stdout, "\n\n\t\t\t\t  After swap list");
	display(myList);
	
	return myList;
}
// ------------------------------------------------------
struct LList* ReverseList(struct LList *myList)
{
	struct node *front, *behind;

	/* Algorithm Description 
		
		Swap head and tail, and next head 
		and previous tail
	*/

	if (myList != NULL)
	{
		front = myList->head;
		behind = myList->tail;
		
		while(front != NULL)
		{
			myList = ReverseSwapNode(myList, front, behind);
			front = front->next;
			behind = behind->previous;
		}
	}
	else
	{
		exit(0);
	}

	return myList;
}
// ------------------------------------------------------
struct LList* ReverseSwapNode(struct LList* myList, 
							  struct node *front, 
							  struct node *behind)
{
	struct node *dummy;

	if (myList != NULL)
	{
		dummy = (struct node *)malloc(sizeof(struct node));
		assert(dummy != NULL);
		dummy->value = front->value;
		front->value = behind->value;
		behind->value = dummy->value;
	}
	else
	{
		exit(0);
	}

	if (front->previous == NULL && behind->next == NULL)
	{
		behind->previous = NULL;
		front->next = NULL;
	}
	else
	{
	}

	free(dummy);

	return myList;
}
// ------------------------------------------------------
int count_specific_value(struct LList *myList)
{
	struct node *traversal;
	int length = 1;
	int value, number = 0;

	if (myList != NULL)
	{
		fprintf(stdout, "\n\n\t\t\t\tEnter a value to count : ");
		scanf("%d", &value);

		traversal = myList->head;

		length = 1;
		while (traversal != NULL)
		{
			if (value == traversal->value)
			{
				number++;
			}
			traversal = traversal->next;
			length++;
		}
		fprintf(stdout, "\n\n\t\t\tValue %d has exist %d times in list\n", value, number);
	}
	else
	{
		exit(0);
	}

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

		do
		{
			fprintf(stdout, "\n\n\t\t\tEnter an index to retrieve a value : ");
			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);
	}
	else
	{
		exit(0);
	}

	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;
	
	if (myList != NULL)
	{
		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;
}
// ------------------------------------------------------
int Middle_of_List(struct LList *myList)
{
	int middle, length;
	float remainder;

	if (myList != NULL)
	{
		length = length_of_List(myList);

		if (length % 2 != 0)
		{
			remainder = length % 2;
			if (remainder >= 0.5)
			{
				middle = (length / 2) + 1;
				fprintf(stdout, "\n\n\t\t\t\tMiddle of Link List is at index %d", middle);
			}
			else
			{
				middle = length / 2;
				fprintf(stdout, "\n\n\t\t\t\tMiddle of Link List is at index %d", middle);
			}
		}
		else
		{
			middle = length / 2;
			fprintf(stdout, "\n\n\t\t\tMiddle of Link List is at index %d", middle);
		}
	}
	else
	{
		exit(0);
	}

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

	struct node *traversal;
	int length;

	if (myList != NULL)
	{
		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++;
		}
	}
	else
	{
		exit(0);
	}
	
}
// ------------------------------------------------------
int Main_menu()
{
	int choice;

	fprintf(stdout, "\n\n\n\t\t\t\t\tMain Menu");
	fprintf(stdout,	"\n\n\n\t\t\t\t   1. Double Link List");
	fprintf(stdout,	"\n\t\t\t\t   2. Order Double Circular Link List");
	fprintf(stdout,	"\n\t\t\t\t   3. Skip List");
	fprintf(stdout,	"\n\t\t\t\t   4. Adjacency List");
	fprintf(stdout,	"\n\t\t\t\t   5. Binary Search Tree\n\n\t\t\t\t      Enter a choice : ");
	
	scanf("%d", &choice); 

	return choice;
}
// ------------------------------------------------------
int DLL_Function()
{
	int choice;


	fprintf(stdout, "\n\n\t\t\t\t    Double Link List Function\n"); 

	fprintf(stdout, "\n\n\n\t\t\t\t\t1. List allocate\n\t\t\t\t\t2. Node Allocate");
	fprintf(stdout, "\n\t\t\t\t\t3. User Input\n\t\t\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t\t\t5. Insert Behind\n\t\t\t\t\t6. Insert Front");
	fprintf(stdout, "\n\t\t\t\t\t7. Random Insert\n\t\t\t\t\t8. Remove Behind");
	fprintf(stdout, "\n\t\t\t\t\t9. Remove Front\n\t\t\t\t\t10. Random Remove");
	fprintf(stdout, "\n\t\t\t\t\t11. Remove Duplicates\n\t\t\t\t\t12. Merge List");
	fprintf(stdout, "\n\t\t\t\t\t13. Swap Node\n\t\t\t\t\t14. Split List");
	fprintf(stdout, "\n\t\t\t\t\t15. Count Value\n\t\t\t\t\t16. Get Value");
	fprintf(stdout, "\n\t\t\t\t\t17. Middle\n\t\t\t\t\t18. Length");
	fprintf(stdout, "\n\t\t\t\t\t19. Interwine\n\t\t\t\t\t20. Reverse List");
	fprintf(stdout, "\n\t\t\t\t\t21. Display");

	fprintf(stdout, "\n\n\t\t\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
}
// ------------------------------------------------------
int ODCLL_Function()
{
	int choice;

	fprintf(stdout, "\n\n\t\t\t\t  Order Double CircularLink List Function\n");
	
	fprintf(stdout, "\n\n\n\t\t\t\t\t1. List allocate\n\t\t\t\t\t2. Node Allocate");
	fprintf(stdout, "\n\t\t\t\t\t3. User Input\n\t\t\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t\t\t5. Sorted Insert\n\t\t\t\t\t6. Remove Behind");
	fprintf(stdout, "\n\t\t\t\t\t7. Display");

	fprintf(stdout, "\n\n\t\t\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
}



Before this i asked you about the insert,w here i null the ehad pointer.

If head is null, then insert first node, else insert second .. node.

How about your solution ..

Besides that, i don't know how to wrote reverse. My logic is swap head node with tail node and next.


Moreover, i also have problem in remove duplicates.

A billion thanks for your helpa dn advice.
  #32  
Old 24-Mar-2008, 21:58
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Link List In C


CPP / C++ / C Code:

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

#include "Link_List.h"
#include "BST.h"

#include "BST.c"

/*#include "Skip_List.h"

#include "Skip_List.c"
*/

// --------------------------------------------------------
/*
Double Link List
Double Circular Link List
Associate Link List
Adjacency List 
Skip List

Floyd's Cycle-Finding Algorithm(The Tortoise and the Hare Algorithm)
Josephus problem

Searching
move-to-front heuristic = Once an elemnt found move to 
                          first node
Range search
Bi-Directional search
Linear search
Binary search

Sorting 
Library Sort
Merge Sort
Radix sort
Bucket Sort
Introsort - Musser, David

Index
[url]http://www.codeuu.com/[/url]
[url]http://www.nist.gov/dads/[/url]
[url]http://www-igm.univ-mlv.fr/~lecroq/string/node31.html[/url]
[url]http://www.thescripts.com/forum/thread708138.html[/url]


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


Memory Checking
these are some popular bounds-checking implementations
ccured [url]http://manju.cs.berkeley.edu/ccured/[/url]
cyclone [url]http://www.research.att.com/viewProject.cfm?prjID=67[/url]
splint [url]http://www.splint.org/[/url]
tinycc [url]http://fabrice.bellard.free.fr/tcc/[/url]
valgrind [url]http://valgrind.org/info/[/url]
rational purify [url]http://www-306.ibm.com/software/awdtools/purify/[/url]
electric fence [url]http://directory.fsf.org/project/ElectricFence/[/url]

parasoft insure++ [url]http://www.parasoft.com/jsp/products...product=Insure[/url]

MemCheck Deluxe
MemWatch
Memtest86
asmem
more information: [url]http://www.doc.ic.ac.uk/teaching/pro...ewSuffield.pdf[/url]


 Steensgaard’s algorithm

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

	/*
		BST object
	*/

	struct BST *BST = 0;
	struct Tree_Node *Tree_Node = 0, *resultSearched=0;

	int *numberptr;

	int number, Main_MenuChoice, DLL_choice, 
		BST_choice, ODCLL_choice, 
		numberList, result, resultNumber,
		numberSplit = 0, middle, length, 
		myListDe_allocate = 0, 
		myListSecondDe_allocate = 0,
		BST_De_allocate = 0,
		tree_input, BST_search;

	int *ismyListDe_allocate,
		*ismyListSecondDe_allocate,
		*BST_input, *searchptr,
		*isBST_De_allocate;

	char Main_menu_continue = 'y', DLL_continue = 'y', 
		ODCLL_continue = 'y', SL_continue = 'y',
		BST_continue = 'y';

	numberptr = &number;
	
	ismyListDe_allocate = &myListDe_allocate;
	ismyListSecondDe_allocate = &myListSecondDe_allocate;
	isBST_De_allocate = &BST_De_allocate;
	
	BST_input = &tree_input;
	searchptr = &BST_search;
	
	draw();

	do
	{
		Main_MenuChoice = Main_menu();

		switch(Main_MenuChoice)
		{
			case 1:
			{
				do
				{
					DLL_choice = DLL_Function();

					switch(DLL_choice)
					{
						case 1:
						{
							numberList = number_list();

							if (numberList == 1)
							{
								myList = list_allocate(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = list_allocate(myListSecond);
							}
							break;
						}

						case 2:
						{
							node = node_allocate();
							break;
						}

						case 3:
						{
							userInput(numberptr, node);
							break;
						}

						case 4:
						{
							Initialize_node(node, numberptr);
							break;
						}

						case 5:
						{
							if (numberList == 1)
							{
								myList = InsertBehind(myList, node);
							}
							else if (numberList == 2)
							{
								myListSecond = InsertBehind(myListSecond, node);
							}
							break;
						}

						case 6:
						{
							if (numberList == 1)
							{
								myList = InsertFront(myList, node);
							}
							else if (numberList == 2)
							{
								myListSecond = InsertFront(myListSecond, node);
							}
							break;
						}

						case 7:
						{
							if (numberList == 1)
							{
								myList = RandomInsert(myList, node);
							}
							else if (numberList == 2)
							{
								myListSecond = RandomInsert(myListSecond, node);
							}
							break;
						}
					
						case 8:
						{
							if (numberList == 1)
							{
								myList = RemoveBehind(myList);
							}
								else if (numberList == 2)
							{
								myListSecond = RemoveBehind(myListSecond);
							}
							break;
						}

						case 9:
						{
							if (numberList == 1)
							{
								myList = RemoveFront(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = RemoveFront(myListSecond);
							}
							break;
						}
				
						case 10:
						{
							if (numberList == 1)
							{
								myList = RandomRemove(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = RandomRemove(myListSecond);
							}
							break;
						}

						case 11:
						{
							if (numberList == 1)
							{
								myList = RemoveDuplicates(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = RemoveDuplicates(myListSecond);
							}
							break;
						}
				
						case 12:
						{
							myList = MergeList(myList, myListSecond);
							break;
						}

						case 13:
						{
							if (numberList == 1)
							{
								myList = SwapNode(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = SwapNode(myListSecond);
							}
							break;
						}
				
						case 14:
						{
							if (numberList == 1)
							{
								SplitList(myList);
							}
							else if (numberList == 2)
							{
								SplitList(myListSecond);
							}				
							break;
						}

						case 15:
						{
							if (numberList == 1)
							{
								resultNumber = count_specific_value(myList);
							}
							else if (numberList == 2)
							{
								resultNumber = count_specific_value(myListSecond);
							}
							break;
						}	
					
						case 16:
						{
							if (numberList == 1)
							{
								result = get_Value_at_index(myList);
							}
							else if (numberList == 2)
							{
								result = get_Value_at_index(myListSecond);
							}
							break;
						}

						case 17:
						{
							if (numberList == 1)
							{
								length = length_of_List(myList);
								myList = MergeSort(myList, length);
							}
							else if (numberList == 2)
							{
								length = length_of_List(myList);
								myListSecond = MergeSort(myListSecond, length);
							}
							break;
						}

						case 18:
						{
							if (numberList == 1)
							{
								BinarySearch(myList);
								BiDirectionSearch(myList);
								RangeSearch(myList);
							}
							else if (numberList == 2)
							{
								BinarySearch(myListSecond);
								BiDirectionSearch(myListSecond);
								RangeSearch(myListSecond);
							}

							break;
						}

						case 19:
						{
							if (numberList == 1)
							{
								middle = Middle_of_List(myList);
							}
							else if (numberList == 2)
							{
								middle = Middle_of_List(myListSecond);
							}
							break;
						}
					
						case 20:
						{
							if (numberList == 1)
							{
								length = length_of_List(myList);
							}
							else if (numberList == 2)
							{
								length = length_of_List(myListSecond);
							}
							break;
						}

						case 21:
						{	
							myList = Interwine(myList, myListSecond);
							break;
						}
					
						case 22:
						{
							if (numberList == 1)
							{
								myList = ReverseList(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = ReverseList(myListSecond);
							}
						}

						case 23:
						{
							if (numberList == 1)
							{
								display(myList);
							}
							else if (numberList == 2)
							{
								display(myListSecond);
							}
							break;
						}

						case 24:
						{
							if (numberList == 1)
							{
								ismyListDe_allocate = list_deallocate(myList, ismyListDe_allocate);
							}
							else if (numberList == 2)
							{
								ismyListSecondDe_allocate = list_deallocate(myListSecond, ismyListSecondDe_allocate);
							}
						}

						case 25:
						{
							numberList = number_list();
						}
					
						default:
						{
							fprintf(stdout, "\n\n\t\t\tInvalid Choice");
							break;
						}
					}

					// fflush must put before scanf
					fflush(stdin);
					fprintf(stdout, "\n\n\t\tDouble Link List Continue : ");
					scanf("%c", &DLL_continue);
				
				}while(DLL_continue == 'y');
					
				break;
			}
			case 2:
			{
				do
				{
					ODCLL_choice = ODCLL_Function();

					switch(ODCLL_choice)
					{
						case 1:
						{
							numberList = number_list();

							if (numberList == 1)
							{
								myList = list_allocate(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = list_allocate(myListSecond);
							}
							break;
						}

						case 2:
						{
							node = node_allocate();
							break;
						}

						case 3:
						{
							userInput(numberptr, node);
							break;
						}

						case 4:
						{
							Initialize_node(node, numberptr);
							break;
						}

						case 5:
						{
							if (numberList == 1)
							{
								myList = SortedInsert(myList, node);
							}
							else if (numberList == 2)
							{
								myListSecond = SortedInsert(myListSecond, node);
							}
							break;
						}

						case 6:
						{
							if (numberList == 1)
							{
								myList = RemoveBehind(myList);
							}
							else if (numberList == 2)
							{
								myListSecond = RemoveBehind(myListSecond);
							}
							break;
						}

						case 7:
						{
							if (numberList == 1)
							{
								display(myList);
							}
							else if (numberList == 2)
							{
								display(myListSecond);
							}
							break;
						}

						case 8:
						{
							if (numberList == 1)
							{
								ismyListDe_allocate = list_deallocate(myList, ismyListDe_allocate);
							
							}
							else if (numberList == 2)
							{
								ismyListSecondDe_allocate = list_deallocate(myListSecond, ismyListSecondDe_allocate);
							}	
						}
						default:
						{
							fprintf(stdout, "\n\n\t\t\tInvalid Choice");
							break;
						}
					}
					// fflush must put before scanf
					fflush(stdin);
					fprintf(stdout, "\n\n\t\tOrder Double Link List Continue : ");
					scanf("%c", &ODCLL_continue);
				
				}while(ODCLL_continue == 'y');
				 break;
			}

			case 4:
			{
				break;
			}

			case 5:
			{
				do
				{
					BST_choice = BST_Function();
				
					switch(BST_choice)
					{
						case 1:
						{
							 BST = BST_Allocate(BST);
							break;
						}
					
						case 2:
						{
							Tree_Node = Tree_Node_Allocate(Tree_Node);
							break;
						}

						case 3:
						{
							BST_UserInput(BST_input);
							break;
						}

						case 4:
						{
							Tree_Node = Tree_Node_Initialize(Tree_Node, BST_input);
							break;
						}

						case 5:
						{
							BST = BST_Insert(BST, Tree_Node);
							break;
						}

						case 6:
						{		
							BST = BST_Remove(BST ,BST_input); 
							break;
						}

						case 7:
						{
							searchptr = QuerySearchValue(searchptr);
							resultSearched = Searching(BST, searchptr);
							SearchDisplay(resultSearched, searchptr);
							break;
						}

						case 8:
						{
							PreorderDisplay(BST); 
							InorderDisplay(BST);
							PostorderDisplay(BST);
							break;
						}

						case 9:
						{
							FindMin(BST);
							break;
						}

						case 10:
						{
							FindMax(BST);
							break;
						}

						case 11:
						{
							isBST_De_allocate = BST_Deallocate(BST, isBST_De_allocate);
							break;
						}
					}

					fflush(stdin);
					fprintf(stdout, "\n\n\t\t\t  BST Continue : ");
					scanf("%c", &BST_continue);

				}while(BST_continue == 'y');

				break;				
			}

			default:
			{
				break;
			}
		}

		fflush(stdin);
		fprintf(stdout, "\n\n\t\t\tMain Menu Continue : ");
		scanf("%c", &Main_menu_continue);

	}while(Main_menu_continue == 'y');


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

	myListSecond = list_allocate(myListSecond);
	node = node_allocate();
	userInput(numberptr, node);
	Initialize_node(node , numberptr); 
	myListSecond = InsertBehind(myListSecond, node);

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


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

	display(myList);

	length = length_of_List(myList);
	
	BinarySearch(myList);

	BiDirectionSearch(myList);
	RangeSearch(myList);
*/



	// To prevent user forget to deallocate memory
	/*
		If overhead occurs here but save stack memory
		rather than calling the function
	*/
	if (*ismyListDe_allocate == 0)
	{
		list_deallocate(myList, ismyListDe_allocate);
	}

	if (*ismyListSecondDe_allocate == 0)
	{
		list_deallocate(myListSecond, ismyListSecondDe_allocate);	
	}

	if (*isBST_De_allocate == 0)
	{
		BST_Deallocate(BST, isBST_De_allocate);
	}



	return 0;
}
// -------------------------------------------------------
void draw()
{
	int loop;

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

	for (loop=0;loop<60;loop++)
	{
		printf("-");
	}
	
	printf("\n\n\t  Welcome to newly Link List Program");
	printf("\n\n  ");
	for (loop=0;loop<60;loop++)
	{
		printf("-");
	}
	printf("\n\n\n\n\n");
	
}
// -------------------------------------------------------
int number_list()
{
	int number;

	fprintf(stdout, "\n\n\t\t   Which list to allocate : ");
	scanf("%d", &number);

	return number;
}
// --------------------------------------------------------
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
	*/

	Initialize_List(myList); // Initilize Link List
	fprintf(stdout, "\n\n\t\t    Memory Allocation successful");

	return myList;
}
// -------------------------------------------------------
int* list_deallocate(struct LList *myList, int *isListDeallocate)
{
	struct node *RemoveNode, *traversal;

	if (myList != NULL && isListDeallocate == 0)
	{
		RemoveNode = myList->head;
		traversal = myList->head;

		while(traversal != NULL)
		{
			traversal = traversal->next;
			if (traversal != NULL)
			{
				traversal->previous = NULL;
			}
			RemoveNode->next = NULL;
			node_deallocate(RemoveNode);
			if (traversal != NULL)
			{
				myList->head = traversal;		
				RemoveNode = myList->head;
			}
		}
		free(myList);
		*isListDeallocate = 1;
	}
	else
	{
		exit(0);
	}

	return isListDeallocate;
}
// -------------------------------------------------------
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)
	{
		return 1;
	}// Three control structure
	else
	{
		fprintf(stdout, "\n\n\t\t\tMemory 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);
	}
}	
// ---------------------------------------------
int node_validateIsAlloc(struct node *node)
{
	// If allocation is successful, then return true
	if (node != NULL)
	{
		fprintf(stdout, "\n\n\t\tNode Memory Allocation successful");
		return 1;
	}
	else
	{
		fprintf(stdout, "Memory exhausted");
		return 0;
	}
}
// -------------------------------------------------------
void Initialize_node(struct node *node, int * numberptr)
{
	if (node != NULL)
	{
		node->next = NULL;
	
		node->customerNumber = *numberptr;
	}
}
// -------------------------------------------------------
struct LList* InsertBehind(struct LList *myList, struct node *node)
{	
	if (myList != NULL)
	{
		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;
			}
		}
	}
	else
	{
		return myList;
	}

	return myList;
}
// -------------------------------------------------------
struct LList* InsertFront(struct LList *myList, struct node *node)
{
	struct LList *tempHead;
	
	if (myList != NULL)
	{
		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);
	}
	else
	{
		return myList;
	}

	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; 

	
	if (myList != NULL)
	{
		traversal_First = myList->head;
		traversal_Second = myList->head;
		dummy_one = myList->head;
		dummy_two = myList->head;

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

					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++;
				}
			}
		}while( Validate_Index(myList, index) == 0);
	}
	else
	{
		return myList;
	}
	return myList;
}
// ------------------------------------------------------
struct LList* SortedInsert(struct LList *myList, struct node *node)
{
	struct node *traversal, *traversal_before;
	int length;

	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_before = myList->head;

		if (myList->head == NULL)
		{
			myList->head = node;
			myList->tail = node;	// Traversal ptr          

			// Circular
	//		myList->tail->next = myList->head;
		}
		else
		{
			length = 1;
			while(traversal->next != NULL 
				&& traversal->customerNumber < node->customerNumber)
			{
				traversal = traversal->next;
				traversal_before = traversal_before->next;
				length++;
			}
			// Insert after traversal
			if (traversal->customerNumber < node->customerNumber)
			{
				if (traversal->next != NULL)
				{
					// Node next point to traversal next
					/* 
						1(traversal)
						2(node)
						3(traversal->next)
					*/
					node->next = traversal->next;
					// 2 -> 3
				}
				traversal->next = node;
				node->previous = traversal;

				while(traversal->next != NULL)
				{
					traversal = traversal->next;
					myList->tail = traversal;
				}
			}
			// Insert before traversal
			else
			{
				if (length == 1)
				{
					node->next = traversal;
					traversal->previous = node;
					myList->head = node;
					myList->tail = node;
				}
				else
				{
					traversal_before = traversal_before->previous;

					traversal_before->next = node;
					node->previous = traversal_before;

					node->next = traversal;
					traversal->previous = node;		
				}
			}
		}
	}
	else
	{
		exit(0);
	}
	traversal = myList->head;

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

	myList->tail = traversal;

	return myList;
}
// ------------------------------------------------------
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);

	if (myList != NULL)
	{
		do
		{
			fprintf(stdout, "\n\n\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
		{
			if (myList->tail != NULL)
			{
				dummy = myList->tail;
				myList->tail = myList->tail->previous;
				dummy->customerNumber = 0;
				node_deallocate(dummy); // free what pointed by dummy  Error
			}
			length--;
		}while(length != numberNode);

		if (myList->tail != NULL)
		{
			myList->tail->next = NULL;
		}
	}
	else
	{
		return myList;
	}
	return myList;

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


	if (myList != NULL)
	{
		removeHead = myList->head;
		removeTail = myList->head;
		traversal = myList->head;
		dummy = myList->head;
		do
		{
			fprintf(stdout, "\n\n\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->customerNumber = 0;
			node_deallocate(dummy);

		}while(traversal != NULL);
	}
	else
	{
		return myList;
	}

	return myList;
}
// -------------------------------------------------------
struct LList* RandomRemove(struct LList *myList)
{ 
	struct node *traversal, *traversal_first, 
		*middle, *middle_two, *freeNode;

	int indexOne, indexTwo, length, remove_length; // To form a range

	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_first = myList->head;
		middle = myList->head;
		middle_two = myList->head;
	
		length = length_of_List(myList);
		fprintf(stdout, "\n\n\t\t   Enter an index or range to remove : ");
	
		do
		{
			fprintf(stdout, "\n\n\t\t   Enter random remove first index : ");
			scanf("%d", &indexOne);

			fprintf(stdout, "\n\n\t\t   Enter random remove second index : ");
			scanf("%d", &indexTwo);
		}while(indexOne > length || indexTwo > length || indexOne == 0);

		// Range Remove
		if (indexTwo != 0)
		{
			length = 1;
			while(traversal_first->next != NULL 
				|| indexTwo >= length)
			{
				if (indexTwo >= length)
				{
					traversal_first = traversal_first->next;
					middle_two = middle_two->next;
				}

				if (length < indexOne)
				{
					traversal = traversal->next;	
					middle = middle->next;
				}
	
				if (indexOne == length)
				{
					traversal = traversal->previous;
				//	traversal->next = NULL;
				}

				if (length - 1 == indexTwo)
				{
					middle_two = middle_two->previous;
					//middle_two->next = NULL;
		
					traversal_first->previous = NULL;
					remove_length = (indexTwo - indexOne) + 1;

					length = 1;
					while(length <= remove_length)
					{
						freeNode = middle;
						if (middle->next != NULL)
						{
							middle = middle->next;
						}
						freeNode = freeNode;
						middle->previous = NULL;

						freeNode->customerNumber = 0;
						freeNode->previous = NULL;
						node_deallocate(freeNode);
						length++;
				
					}

					traversal->next = traversal_first;
		
					traversal_first->previous = traversal;
				}
				length++;
			}
		}
		// Single Random Remove
		else
		{
			length = 1;
			while(indexOne >= length)
			{
				if (indexOne == length)
				{
					traversal = traversal->previous;
					traversal_first = traversal_first->next;

					traversal->next = traversal_first;
					traversal_first->previous = traversal;
				
					middle->customerNumber = 0;
					node_deallocate(middle);
				}
				traversal = traversal->next;
				traversal_first = traversal_first->next;
				middle = middle->next;
				length++;
			}
		}
	}
	else
	{
		exit(0);
	}

	return myList;
}
// -------------------------------------------------------
struct LList* RemoveDuplicates(struct LList *myList)
{
	struct node *traversal, *traversal_before, 
		*traversal_remove, *traversal_after;
	int temp_length = 1, length, inner_loop = 1;
	char deallocate = 'n';

	if (myList != NULL)
	{
		traversal = myList->head;
		traversal_remove = myList->head;
		traversal_before = myList->head;
		traversal_after = myList->head;
		length = length_of_List(myList);
	
		// Compare and to remove duplicates
	
		while(traversal != NULL)
		{
			traversal_remove = myList->head;
			traversal_before = myList->head;
			traversal_after = myList->head;
		
			inner_loop = 1;
			while(traversal_after != NULL)
			{
				deallocate = 'n';
				if (temp_length == inner_loop)
				{
					if (traversal_after->next != NULL)
					{
						traversal_remove = traversal_remove->next;
						traversal_before = traversal_before->next;
						traversal_after = traversal_after->next;
						inner_loop++;
					}
				}
				
				// Two customers can have same name but not customer number
				if (traversal->customerNumber == traversal_remove->customerNumber
					&& temp_length != inner_loop)
				{
					if (traversal_remove->next == NULL && inner_loop == length)
					{
						traversal_before = traversal_before->previous;
						traversal_before->next = NULL;
						deallocate = 'y';
					}
					else
					{
						traversal_before = traversal_before->previous;
						if (traversal_after->next != NULL)
						{
							traversal_before->next = traversal_after->next;
							traversal_after->next->previous = traversal_before;
							deallocate = 'y';
						}
					}
				}
		
				traversal_after = traversal_after->next;
				traversal_before = traversal_after;
				
				if (deallocate == 'y')
				{
					node_deallocate(traversal_remove);
				}
		
				traversal_remove = traversal_after;
				inner_loop++;
			}
			traversal = traversal->next;
			temp_length++;
		}
	}
	else
	{
		return myList;
	}

	/*
		Remove Duplicates operate in quadratic time
		when implemented with two nested loop
		O(n ^ 2)
	*/
	return myList;
}
// -------------------------------------------------------
struct LList* ReverseList(struct LList *myList)
{
	struct node *dummy, *traversal_before, *traversal, *tmp_head;

	/* Algorithm Description 
		
		  Reverse single LL
		Node *Reverse (Node *p)
		{
			Node *pr = NULL;
			while (p != NULL)
			{
				Node *tmp = p->next;
				p->next = pr;
				pr = p;
				p = tmp;
			}
			return pr;
		}

		Swap head and tail, and next head 
		and previous tail
		
		if its a doubly linked list then just 
		swap the prev and next pointers for each node and make the current tail as head.
        else ricki'sanswer would be fine
	*/

	if (myList != NULL)
	{
		traversal_before = myList->head;
		traversal = myList->head;
		dummy = myList->head;
		tmp_head = myList->head;

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

			dummy = traversal_before->previous;
			traversal_before->previous = traversal_before->next;
			traversal_before->next = dummy;
		
			traversal_before = traversal;
		}
		tmp_head = myList->head;
		myList->head = myList->tail;
		myList->tail = tmp_head;
	}
	else
	{
		exit(0);
	}

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

	
	if (first != NULL && second != NULL)
	{
		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);
	}
	else
	{
		return first;
	}

	return first;
}
// -------------------------------------------------------
struct LList* MergeSort(struct LList *myList, int length)
{
	struct LList *left, *right;
	struct node *traversal;
	int numberLeft, numberRight, loop = 1;

	if (myList != NULL)
	{
		left = (struct LList *)malloc(sizeof(struct LList));
		assert(left != 0);

		right = (struct LList *)malloc(sizeof(struct LList));
		assert(right != 0);

		length = length_of_List(myList);

		numberLeft = length / 2;
		numberRight = length - numberLeft;

		if (length < 2)
		{
			return myList;
		}

		traversal = myList->head;
		while(loop < numberLeft)
		{
			traversal = traversal->next;
			loop++;
		}

		left->head = myList->head;       // Left->head
		right->head = traversal->next;   // right->head

		left->tail = traversal;		     // Left->tail 
		traversal->next = NULL;

		traversal = right->head;
		traversal->previous = NULL;

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

		right->tail = traversal;        // right->tail 
	
		left = MergeSort(left, numberLeft);
		right = MergeSort(right, numberRight);

		myList = Merge(left, right);
	}
	else
	{
		exit(0);
	}
	return myList;

	if (left != NULL)
	{
		free(left);
	}
	if (right != NULL)
	{
		free(right);
	}
	/*
		Merge Sort and Quick sort operate in 
		O(n log n) time
	*/
}
// -------------------------------------------------------
struct LList* Merge(struct LList *left, struct LList *right)
{
	struct LList *myList = 0;
	struct node *traversal_left_current = 0,
		*traversal_right_current = 0, 
		*mark_Traversal_Previous = 0,
		*mark_Traversal_Current = 0;

	if (left != NULL || right != NULL)
	{
		myList = (struct LList *)malloc(sizeof(struct LList));
		assert(myList != 0);

		myList->head = NULL;
		myList->tail = NULL;

		// To handle odd or unbalanced number list
		if (left == NULL)
		{
			return right;
		}
		if (right == NULL)
		{
			return left;
		}
		
		traversal_left_current = left->head;
		traversal_right_current = right->head;

		while(traversal_left_current != NULL 
			|| traversal_right_current != NULL)
		{
			if (myList->head == NULL)
			{
				if (traversal_left_current->customerNumber 
					< traversal_right_current->customerNumber)
				{
					myList->head = traversal_left_current;
					myList->tail = traversal_left_current;

					if (traversal_left_current != NULL)
					{
						traversal_left_current = traversal_left_current->next;
						
						if (traversal_left_current != NULL)
						{
							traversal_left_current->previous = NULL;
						}
					}
					myList->head->next = NULL;
					myList = myList;
				}
				else
				{
					myList->head = traversal_right_current;
					myList->tail = traversal_right_current;

					if (traversal_right_current != NULL)
					{
						traversal_right_current = traversal_right_current->next;

						if (traversal_right_current != NULL)
						{
							traversal_right_current->previous = NULL;
						}
					}
					myList->head->next = NULL;
				}
			}
			else
			{
				// To add unsorted last element to sorted myList
				if (traversal_left_current != NULL 
					&& traversal_right_current == NULL)
				{
					myList->tail->next = traversal_left_current;
					if (myList->tail->next != NULL)
					{
						myList->tail = myList->tail->next;
						if (traversal_left_current != NULL)
						{
							traversal_left_current = traversal_left_current->next;
						}
						myList->tail->next = NULL;
					}
				}

				// To add unsorted last element to sorted myList
				if (traversal_right_current != NULL
					&& traversal_left_current == NULL)
				{
					myList->tail->next = traversal_right_current;
					if (myList->tail->next != NULL)
					{
						myList->tail = myList->tail->next;
						if (traversal_right_current != NULL)
						{
							traversal_right_current = traversal_right_current->next;
						}
						myList->tail->next = NULL;
					}	
				}
				
				if (traversal_left_current != NULL 
					&& traversal_right_current != NULL)
				{
					if (traversal_left_current->customerNumber 
						< traversal_right_current->customerNumber)
					{
						myList->tail->next = traversal_left_current;

						if (traversal_left_current != NULL)
						{
							traversal_left_current = traversal_left_current->next;

							if (traversal_left_current != NULL)
							{	
								traversal_left_current->previous = NULL;
							}
						}
						if (myList->tail->next != NULL)
						{
							myList->tail = myList->tail->next;
						}
					}
					else
					{
						myList->tail->next = traversal_right_current;

						if (traversal_right_current != NULL)
						{
							traversal_right_current = traversal_right_current->next;

							if (traversal_right_current != NULL)
							{
								traversal_right_current->previous = NULL;
							}
						}
						if (myList->tail->next != NULL)
						{
							myList->tail = myList->tail->next;
						}
					}
				}
			}
		}
	}
	else
	{
		exit(0);
	}

	mark_Traversal_Previous = myList->head;
	mark_Traversal_Current = myList->head;

	while(mark_Traversal_Current->next != NULL)
	{
		mark_Traversal_Current = mark_Traversal_Current->next;
		mark_Traversal_Current->previous = mark_Traversal_Previous;
		mark_Traversal_Previous = mark_Traversal_Previous->next;
	}

	return myList;

	if (myList != NULL)
	{
		free(myList);
	}
}
// -------------------------------------------------------
struct LList* Interwine(struct LList *myList, struct LList *myListSecond)
{
	// Traversal for first and second list
	struct node *traversal_first, *traversal_second;
	// Traversal for first list after current
	struct node *traversal_next;

	// General length, first list length and second list length
	int length, first_length, second_length;

	/*  
		Interwine example  
		
		First List - 6,3,8,1,44
		Second List - 9,-3,10,100,54

		Result - 6,9,3,-3,8,10,1,100,44,54
    */
	
	first_length = length_of_List(myList);
	second_length = length_of_List(myListSecond);

	if (first_length >= 2 && second_length >= 2)
	{
		if (myList != NULL && myListSecond != NULL)
		{
			traversal_first = myList->head;
			traversal_second = myListSecond->head;

			// Point at second node of first list 
			traversal_next = myList->head->next;

			length = 1;
			do 
			{
				// Algorithm 
			
				// Pointing
				if (myListSecond->head->next != NULL)
				{
					myListSecond->head = myListSecond->head->next;
				}

				if (length != 1 && length != second_length)
				{
					traversal_second = myListSecond->head->previous;
				}

				if (length == second_length)
				{
					traversal_second = myListSecond->head;
				}

				traversal_first->next = traversal_second;
				traversal_second->previous = traversal_first;
			
				traversal_second->next = traversal_next;
				
				if (traversal_next != NULL)
				{
					traversal_next->previous = traversal_second;
				}

				if (traversal_first->next != NULL && traversal_first->next->next)
				{
					traversal_first = traversal_first->next->next;
				}

				if (myList->tail != NULL && traversal_next != NULL)
				{
					traversal_next = traversal_next->next;
				}

				if (myList->tail->next != NULL)
				{
					myList->tail = myList->tail->next;
				}

				length++;

				if (length == second_length + 1)
				{
//					myListSecond->head->next = NULL;
//					myListSecond->tail->previous = NULL;
					goto exit;
				}

			}while(myList->tail != NULL);
		}
		else
		{
			exit(0);
		}
	}


exit:
	display(myList);
	free(myListSecond);

//	list_deallocate(myListSecond);

	return myList;
}
// -------------------------------------------------------
void SplitList(struct LList *myList)
{
	int choice; 

	printf("\n\n\t\t\t   1. AI Split\n\t\t\t   2. User Split");
	fprintf(stdout, "\n\n\t\t\t  Enter a Choice : ");
	scanf("%d", &choice);

	switch(choice)
	{
		case 1:
			{
				if (myList != NULL)
				{
					AISplitList(myList);
				}
				break;
			}
		case 2:
			{
				if (myList != NULL)
				{
					UserSplitList(myList);
				}
				break;
			}
		default:
			{
				fprintf(stdout, "Invalid choice");
			}
	}
}
// -------------------------------------------------------
void AISplitList(struct LList *myList)
{
	struct LList *firstList, *secondList, *thirdList, 
		*fourthList, *fifthList;

	// Temp Tail 
	struct node *traversal, *traversal_second, 
		*traversal_third, *traversal_fourth, 
		*traversal_fifth;

	// temp_length indicate location to split
	// real_length indicate real length
	// user_length indicate length to split
	int temp_remainder, user_length, temp_length = 1,  
		numberSplit, real_length, count_list = 1;
	float remainder ;

	traversal = myList->head;
	traversal_second = myList->head;
	traversal_third = myList->head;
	traversal_fourth = myList->head;
	traversal_fifth = myList->head;

	firstList = (struct LList *)malloc(sizeof(struct LList));
	assert (firstList != 0);

	secondList = (struct LList *)malloc(sizeof(struct LList));
	assert (secondList != 0);

	thirdList = (struct LList *)malloc(sizeof(struct LList));
	assert (thirdList != 0);

	fourthList = (struct LList *)malloc(sizeof(struct LList));
	assert (fourthList != 0);

	fifthList = (struct LList *)malloc(sizeof(struct LList));
	assert (fifthList != 0);


	real_length = length_of_List(myList);

	/* 
	   AI
	   This may seems unrealistic in real world database
	   application
    */

	if (real_length <= 10)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 2 List");
	}
	else if (real_length > 10 && real_length <= 20)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 2 and 4 List");
	}
	else if (real_length > 20 && real_length <= 50)
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split is 5 List");
	}
	else
	{
		fprintf(stdout, "\n\n\t\t\tRecommended number of split cannot be achieve");
	}
	
	do
	{
		fprintf(stdout, "\n\n\t\t\t\tHow many list to split : ");
		scanf("%d", &numberSplit);
	}while(numberSplit > real_length && numberSplit == real_length || numberSplit == 0 && numberSplit < 6);
	// Make it as balanced as possible How to split perfect split and not balance split 2-3,3-4(2-5),4-5
	
	user_length = real_length;

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

/*
                                                      UL 
                                                NS    __
                                Remainder < 2   _____|      
                                               |     |__
                   Got         ________________|
				 Remainder    |                |      __
				              |                |_____|
                ______________|                      |__
               |              |
			   |              |
			   |              |________________
			   |              
_______________|                Remainder >= 2
               |                   
               |               ________ NS ________ UL
			   |              |
			   |              |
			   |______________|
	                          |
					 No       |
				  Remainder   |________ NS ________ UL
	
*/	
	
	if (real_length % numberSplit != 0)
	{
		// User length is length of sub list
		// To check remainder
		if (real_length % numberSplit < 2)
		{
			// Remainder 1/2 = 0.5 
		
			temp_remainder = user_length % numberSplit;
			remainder = (float)temp_remainder;
			
			// Handle remainder = 1
			remainder = remainder / numberSplit;
			user_length = user_length / numberSplit;

			if (remainder >= 0.5) 
			{
				user_length = user_length + 1;

				if (numberSplit == 2)
				{
					// 5/2 
					if (user_length == 3)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}

									goto loop;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										goto exit;
									}
									goto loop;
								}
							
							}
							
							loop:
								temp_length++;
							
								if (temp_length > user_length && count_list != 3)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}

					// 7/2
					if (user_length == 4)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}
									goto loop1;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										goto exit;
									}
									goto loop1;
								}
							}
							loop1:
								temp_length++;
							
								if (temp_length > user_length && count_list != 3)
								{
									temp_length = 1;
									count_list++;
								}
						}

					}

					// 9/2
					if (user_length == 5)
					{
						while(traversal_second != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
									}
									goto loop2;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										goto exit;
									}

									goto loop2;
								}
								loop2:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
				}

				// 14/4 
				if (numberSplit == 4)
				{
					if (user_length == 4)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
						
									if (temp_length == 4)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop9;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop9;
								}
								loop9:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
					 
				}
			}
          // Remainder not equal to 0.5
		  // Handle remainder = 2
			else
			{	
				if (numberSplit == 3)
				{
					// 7/3 
					if (user_length == 2)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}
									goto loop3;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop3;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop3;
								}
								loop3:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}
	
					// 13/3
					if (user_length == 4)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}
									goto loop4;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop4;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop4;
								}
								loop4:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
							
					}

					// 16/3
					if (user_length == 5)
					{
						while(traversal_third != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									goto loop5;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
									}
									goto loop5;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4 || temp_length == 5)
									{
										traversal_third = traversal_third->next;
									}

									if (temp_length == 6)
									{
										thirdList->tail = traversal_third;
										goto exit;
									}
									goto loop5;
								}
								loop5:
									temp_length++;
							
									if (temp_length > user_length && count_list != 3)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}
				}

				if (numberSplit == 4)
				{
					// 9/4
					if (user_length == 2)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{

								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									
									if (temp_length == 2)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop6;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop6;
								}
								loop6:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}

					// 13/4
					if (user_length == 3)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;

									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop7;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop7;
								}
								loop7:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 4)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									goto loop26;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop26;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop26;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop26;
								}
								loop26:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}
							}
						}
					}

					if (user_length == 5)
					{
						while(traversal_fourth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
									}
									goto loop27;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fourth = traversal_fourth->next;
									}

									if (temp_length == 5)
									{
										fourthList->tail = traversal_fourth;
										goto exit;
									}
									goto loop27;
								}
								loop27:
									temp_length++;
							
									if (temp_length > user_length && count_list != 4)
									{
										temp_length = 1;
										count_list++;
									}		
							}
						}
					}
				}

				if (numberSplit == 5)
				{
					if (user_length == 2)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										secondList->tail = traversal_second; 
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop28;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop28;
								}
								loop28:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 3)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop29;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 3)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop29;
								}
								loop29:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 4)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										firstList->head = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									goto loop30;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										thirdList->head = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop30;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 4)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop30;
								}
								loop30:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}

					if (user_length == 5)
					{
						while(traversal_fifth != NULL)
						{
							while(count_list <= numberSplit)
							{
								if (count_list == 1)
								{
									if (temp_length == 1)
									{
										firstList->head = traversal;
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal = traversal->next;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										firstList->tail = traversal;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 2)
								{
									if (temp_length == 1)
									{
										secondList->head = traversal_second;
										firstList->tail->next = NULL;
										secondList->head->previous = NULL;
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_second = traversal_second->next;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										secondList->tail = traversal_second;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 3)
								{
									if (temp_length == 1)
									{
										thirdList->head = traversal_third;
										secondList->tail->next = NULL;
										thirdList->head->previous = NULL;
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_third = traversal_third->next;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										thirdList->tail = traversal_third;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 4)
								{
									if (temp_length == 1)
									{
										fourthList->head = traversal_fourth;
										thirdList->tail->next = NULL;
										fourthList->head->previous = NULL;
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fourth = traversal_fourth->next;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										fourthList->tail = traversal_fourth;
										traversal_fifth = traversal_fifth->next;
									}
									goto loop31;
								}

								if (count_list == 5)
								{
									if (temp_length == 1)
									{
										fifthList->head = traversal_fifth;
										fourthList->tail->next = NULL;
										fifthList->head->previous = NULL;
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 2 || temp_length == 3 || temp_length == 4)
									{
										traversal_fifth = traversal_fifth->next;
									}

									if (temp_length == 5)
									{
										fifthList->tail = traversal_fifth;
										goto exit;
									}
									goto loop31;
								}
								loop31:
									temp_length++;
							
									if (temp_length > user_length && count_list != 5)
									{
										temp_length = 1;
										count_list++;
									}	
							}
						}
					}
				}
			}
		}
     // ---------------------------------- 
		// remainder equal or over 2
		else
		{
			user_length = user_length / numberSplit;
			user_length = user_length + 1;

			if (numberSplit == 2)
			{
				if (user_length == 3)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 3)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}
								goto loop32;
							}
	
							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 3)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop32;
							}
							loop32:
								temp_length++;
							
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}	
						}
					}
				}

				if (user_length == 4)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}

								goto loop33;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->next = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop33;
							}
							loop33:
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_second != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
								}

								goto loop34;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->next = NULL;
									traversal_second = traversal_second->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									goto exit;
								}
								goto loop34;
							}
							loop34:
								temp_length++;
								
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}

			if (numberSplit == 3)
			{
				if (user_length == 2)
				{
					while(traversal_third != NULL)
					{
						while(count_list <= numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}
								goto loop35;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									secondList->tail = traversal_second; 
									traversal_third = traversal_third->next;
								}
								goto loop35;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
								}

								if (temp_length == 2)
								{
									thirdList->tail = traversal_third;
									goto exit;
								}
								goto loop35;
							}
							loop35:
								temp_length++;
								
								if (temp_length > user_length && count_list != 2)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 3)
				{
				}

				if (user_length == 4)
				{
				}

				if (user_length == 5)
				{
				}
			}

			if (numberSplit == 4)
			{
				if (user_length == 2)
				{
				}

				if (user_length == 3)
				{
				}

				// 15/4
				if (user_length == 4)
				{
					while(traversal_fourth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 4)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop8;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2)
								{
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 3)
								{
									fourthList->tail = traversal_fourth;
									goto exit;
								}
								goto loop8;
							}
							loop8:
								temp_length++;
							
								if (temp_length > user_length && count_list != 4)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_fourth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal->next;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
								}
								goto loop36;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fourth = traversal_fourth->next;
								}

								if (temp_length == 5)
								{
									fourthList->tail = traversal_fourth;
									goto exit;
								}
								goto loop36;
							}
							loop36:
								temp_length++;
							
								if (temp_length > user_length && count_list != 4)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}

			if (numberSplit == 5)
			{
				if (user_length == 2)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									firstList->head = traversal ;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop37;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop37;
							}
							loop37:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 3)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop38;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 3)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop38;
							}
							loop38:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}	
						}
					}
				}

				if (user_length == 4)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->next = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop39;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 4)
								{
									fifthList->tail =traversal_fifth;
									goto exit;
								}
								goto loop39;
							}
							loop39:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}

				if (user_length == 5)
				{
					while(traversal_fifth != NULL)
					{
						while(count_list <=numberSplit)
						{
							if (count_list == 1)
							{
								if (temp_length == 1)
								{
									firstList->head = traversal;
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal = traversal->next;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									firstList->tail = traversal;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 2)
							{
								if (temp_length == 1)
								{
									secondList->head = traversal_second;
									firstList->tail->next = NULL;
									secondList->head->previous = NULL;
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_second = traversal_second->next;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									secondList->tail = traversal_second;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 3)
							{
								if (temp_length == 1)
								{
									thirdList->head = traversal_third;
									secondList->tail->next = NULL;
									thirdList->head->previous = NULL;
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_third = traversal_third->next;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									thirdList->tail = traversal_third;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 4)
							{
								if (temp_length == 1)
								{
									fourthList->head = traversal_fourth;
									thirdList->tail->previous = NULL;
									fourthList->head->previous = NULL;
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fourth = traversal_fourth->next;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									fourthList->tail = traversal_fourth;
									traversal_fifth = traversal_fifth->next;
								}
								goto loop40;
							}

							if (count_list == 5)
							{
								if (temp_length == 1)
								{
									fifthList->head = traversal_fifth;
									fourthList->tail->next = NULL;
									fifthList->head->previous = NULL;
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 2 || temp_length == 3 || temp_length == 4)
								{
									traversal_fifth = traversal_fifth->next;
								}

								if (temp_length == 5)
								{
									fifthList->tail = traversal_fifth;
									goto exit;
								}
								goto loop40;
							}
							loop40:
								temp_length++;
							
								if (temp_length > user_length && count_list != 5)
								{
									temp_length = 1;
									count_list++;
								}
						}
					}
				}
			}
		}
	}
// --------------------------- 
// No remainder
	else
	{
		user_length = real_length / numberSplit;

		if (numberSplit == 2)
		{
			if (user_length == 2)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop10;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop10;
						}

						loop10:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop11;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop11;
						}
						loop11:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}
							
							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 4)
							{
								firstList->head = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop12;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}
							
							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 4)
							{
								secondList->head = traversal_second;
								goto exit;
							}
							goto loop12;
						}
					}
					loop12:
						if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
				}
			}

			if (user_length == 5)
			{
				while(traversal_second != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
							}
							goto loop13;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								goto exit;
							}
							goto loop13;
						}
						loop13:
							if (temp_length > user_length && count_list != 2)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 3)
		{
			if (user_length == 2)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop14;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop14;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head  = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop14;
						}
						loop14:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}	
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop15;
						}
		
						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop15;
						}	

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop15;
						}
						loop15:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}	
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop16;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop16;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop16;
						}
						loop16:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_third != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}
							goto loop17;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
							}
							goto loop17;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								goto exit;
							}
							goto loop17;
						}
						loop17:
							if (temp_length > user_length && count_list != 3)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 4)
		{
			if (user_length == 2)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop18;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop18;
						}
						loop18:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			// 12/3 
			if (user_length == 3)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop19;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 3)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop19;
						}
						loop19:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			// 16/4
			if (user_length == 4)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop20;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 4)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop20;
						}
						loop20:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_fourth != NULL)
				{
					while(count_list <=numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
							}
							goto loop21;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fourth = traversal_fourth->next;
							}

							if (temp_length == 5)
							{
								fourthList->tail = traversal_fourth;
								goto exit;
							}
							goto loop21;
						}
						loop21:
							if (temp_length > user_length && count_list != 4)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}

		if (numberSplit == 5)
		{
			if (user_length == 2)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal->next;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop22;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop22;
						}
						loop22:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 3)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop23;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 3)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop23;
						}
						loop23:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 4)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop24;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 4)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop24;
						}
						loop24:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}

			if (user_length == 5)
			{
				while(traversal_fifth != NULL)
				{
					while(count_list <= numberSplit)
					{
						if (count_list == 1)
						{
							if (temp_length == 1)
							{
								firstList->head = traversal;
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal = traversal->next;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								firstList->tail = traversal;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 2)
						{
							if (temp_length == 1)
							{
								secondList->head = traversal_second;
								firstList->tail->next = NULL;
								secondList->head->previous = NULL;
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_second = traversal_second->next;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								secondList->tail = traversal_second;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 3)
						{
							if (temp_length == 1)
							{
								thirdList->head = traversal_third;
								secondList->tail->next = NULL;
								thirdList->head->previous = NULL;
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_third = traversal_third->next;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								thirdList->tail = traversal_third;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 4)
						{
							if (temp_length == 1)
							{
								fourthList->head = traversal_fourth;
								thirdList->tail->next = NULL;
								fourthList->head->previous = NULL;
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fourth = traversal_fourth->next;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								fourthList->tail = traversal_fourth;
								traversal_fifth = traversal_fifth->next;
							}
							goto loop25;
						}

						if (count_list == 5)
						{
							if (temp_length == 1)
							{
								fifthList->head = traversal_fifth;
								fourthList->tail->next = NULL;
								fifthList->head->previous = NULL;
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 2 || temp_length == 3 || temp_length == 4)
							{
								traversal_fifth = traversal_fifth->next;
							}

							if (temp_length == 5)
							{
								fifthList->tail = traversal_fifth;
								goto exit;
							}
							goto loop25;
						}
						loop25:
							if (temp_length > user_length && count_list != 5)
							{
								temp_length = 1;
								count_list++;
							}
					}
				}
			}
		}
	}


	// ------------------ Display --------------------

exit: 
	if (traversal == firstList->tail)
	{
		traversal = firstList->head;

		printf("\n\n\t\t\t\t   First List\n\n");
		temp_length = 1;
		while(traversal != NULL && traversal != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal->customerNumber);
			traversal = traversal->next;
			temp_length++;
		}
	}

	if (traversal_second == secondList->tail)
	{
		printf("\n\n\t\t\t\t   Second List\n\n");
		traversal_second = secondList->head;

		temp_length = 1;
		while(secondList != NULL && traversal_second != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_second->customerNumber);
			traversal_second = traversal_second->next;
			temp_length++;
		}
	}

	if (traversal_third == thirdList->tail)
	{
		printf("\n\n\t\t\t\t   Third List\n\n");
		traversal_third = thirdList->head;

		temp_length = 1;
		while(thirdList != NULL && traversal_third != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_third->customerNumber);
			traversal_third = traversal_third->next;
			temp_length++;
		}
	}

	if (traversal_fourth == fourthList->tail)
	{
		printf("\n\n\t\t\t\t   Fourth List\n\n");
		traversal_fourth = fourthList->head;

		temp_length = 1;
		while(fourthList != NULL && traversal_fourth != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_fourth->customerNumber);
			traversal_fourth = traversal_fourth->next;
			temp_length++;
		}
	}

	if (traversal_fifth == fifthList->tail)
	{
		printf("\n\n\t\t\t\t   Fifth List\n\n");
		traversal_fifth = fifthList->head;
			
		temp_length = 1;
		while(fifthList != NULL && traversal_fifth != NULL)
		{
			printf("\t\t\t\tNode %d of List : %d\n", temp_length, traversal_fifth->customerNumber);
			traversal_fifth = traversal_fifth->next;
			temp_length++;
		}
	}

	// ----------------------Free--------------------

	if (firstList != NULL)  
	{
		free(firstList);
	}

	if(secondList != NULL)
	{
		free(secondList);
	}

	if (thirdList != NULL) 
	{
		free(thirdList);

	}
	if(fourthList != NULL)
	{
		free(fourthList);
	}

	if (fifthList != NULL)
	{
		free(fifthList);
	}
}
// ------------------------------------------------------
void UserSplitList(struct LList *myList)
{
	struct node *traversal;
	struct node *firstTail, *secondTail, *thirdTail,
		*fourthTail, *fifthTail;

	struct LList *firstList, *secondList, *thirdList,
		*fourthList, *fifthList;

	int real_length, numberSplit, count_list,
		listOneIndexOne, listOneIndexTwo, 
		listTwoIndexOne, listTwoIndexTwo,
		listThreeIndexOne, listThreeIndexTwo,
		listFourIndexOne, listFourIndexTwo,
		listFiveIndexOne, listFiveIndexTwo,
		length;
	// To indicate range to split by user

	traversal = myList->head;

	thirdList = NULL;
	fourthList = NULL;
	fifthList = NULL;

	if (myList != NULL)
	{
		real_length = length_of_List(myList);
		// To get numberSplit from user
		do
		{
			fprintf(stdout, "\n\n\t\t\tHow many List to split : ");
			scanf("%d", &numberSplit);
		}while(numberSplit > 6 || numberSplit == 0);

		// To get index from user
		count_list = 1;
		do
		{
			if (count_list == 1)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\tList One Index One : ");
					scanf("%d", &listOneIndexOne);
					fprintf(stdout, "\n\t\t\tList One Index Two : ");
					scanf("%d", &listOneIndexTwo);
				}while(listOneIndexOne != 1);

				do
				{
					firstList = (struct LList *)malloc(sizeof(struct LList));
					assert(firstList != 0);
				}while(firstList == NULL);
			}

			if (count_list == 2)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\tList Two Index One : ");
					scanf("%d", &listTwoIndexOne);
					fprintf(stdout, "\n\t\t\tList Two Index Two : ");
					scanf("%d", &listTwoIndexTwo);
				}while(listTwoIndexOne == listOneIndexTwo || listTwoIndexOne - listOneIndexTwo > 1);
				
				do
				{
					secondList = (struct LList *)malloc(sizeof(struct LList));
					assert(secondList != 0);
				}while(secondList == NULL);
			}

			if (count_list == 3)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\tList Three Index One : ");
					scanf("%d", &listThreeIndexOne);
					fprintf(stdout, "\n\t\t\tList Three Index Two : ");
					scanf("%d", &listThreeIndexTwo);
				}while(listThreeIndexOne == listTwoIndexTwo || listThreeIndexOne - listTwoIndexTwo > 1);
			
				do
				{
					thirdList = (struct LList *)malloc(sizeof(struct LList));
					assert(thirdList != 0);
				}while(thirdList == NULL);
			}

			if (count_list == 4)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\tList Four Index One : ");
					scanf("%d", &listFourIndexOne);
					fprintf(stdout, "\n\t\t\tList Four Index Two : ");
					scanf("%d", &listFourIndexTwo);
				}while(listFourIndexOne == listThreeIndexTwo || listFourIndexOne - listThreeIndexTwo > 1);
			
				do
				{
					fourthList = (struct LList *)malloc(sizeof(struct LList));
					assert(fourthList != 0);
				}while(fourthList == NULL);
			}

			if (count_list == 5)
			{
				do
				{
					fprintf(stdout, "\n\n\t\t\tList Five Index One : ");
					scanf("%d", &listFiveIndexOne);
					fprintf(stdout, "\n\t\t\tList Five Index Two : ");
					scanf("%d", &listFiveIndexTwo);
				}while(listFiveIndexOne == listFourIndexTwo || listFiveIndexOne - listFourIndexTwo > 1);
			
				do
				{
					fifthList = (struct LList *)malloc(sizeof(struct LList));
					assert(fifthList != 0);
				}while(fifthList == NULL);
			}
			count_list++;
		}while(count_list <= numberSplit);

		// To split the list specified by user
		length = 1;
		do
		{
			// List 1
			if (length == 1 && listOneIndexOne == length)
			{
				firstList->head = traversal;
			}

			if (listOneIndexTwo == length)
			{
				firstList->tail = traversal;
			}

			// List 2
			if (listTwoIndexOne == length)
			{
				firstList->tail->next = NULL;
				secondList->head = traversal;
				secondList->head->previous = NULL;
			}

			if (listTwoIndexTwo == length)
			{
				secondList->tail = traversal;
			}

			// List 3
			if (listThreeIndexOne != 0)
			{
				if (listThreeIndexOne == length)
				{
					secondList->tail->next = NULL;
					thirdList->head = traversal;
					thirdList->head->previous = NULL;
				}
			}

			if (listThreeIndexTwo != 0)
			{
				if (listThreeIndexTwo == length)
				{
					thirdList->tail = traversal;
				}
			}

			// List 4
			if (listFourIndexOne != 0)
			{
				if (listFourIndexOne == length)
				{
					thirdList->tail->next = NULL;
					fourthList->head = traversal;
					fourthList->head->previous = NULL;
				}
			}

			if (listFourIndexTwo != 0)
			{
				if (listFourIndexTwo == length)
				{
					fourthList->tail = traversal;
				}
			}

			// List 5
			if (listFiveIndexOne != 0)
			{
				if (listFiveIndexOne == length)
				{
					fourthList->tail->next = NULL;
					fifthList->head = traversal;
					fifthList->head->previous = NULL;
				}
			}
			
			if (listFiveIndexTwo != 0)
			{
				if (listFiveIndexTwo == length)
				{
					fifthList->tail = traversal;
				}
			}

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

		// ---------------------Display-----------------

		// List 1
		if (firstList->head != NULL && firstList->tail != NULL)
		{
			firstTail = firstList->head;

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

		// List 2
		if (secondList != NULL)
		{
			secondTail = secondList->head;

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

		// List 3
		if (thirdList != NULL)
		{
			thirdTail = thirdList->head;

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

		// List 4
		if (fourthList != NULL)
		{
			fourthTail = fourthList->head;

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

		// List 5
		if (fifthList != NULL )
		{
			fifthTail = fifthList->head;

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

		// ----------------------Free-------------------

		if (firstList != NULL)  
		{
			free(firstList);
		}

		if(secondList != NULL)
		{
			free(secondList);
		}

		if (thirdList != NULL) 
		{
			free(thirdList);
		}

		if(fourthList != NULL)
		{
			free(fourthList);
		}

		if (fifthList != NULL)
		{
			free(fifthList);
		}

	}
	else
	{
		exit(0);
	}

}
// -------------------------------------------------------
struct LList* SwapNode(struct LList *myList)
{
	struct node *indexFirstNodeBefore, 
		*indexFirstNodeMiddle, *indexFirstNodeAfter,
		*indexSecondNodeBefore, *indexSecondNodeMiddle,
		*indexSecondNodeAfter, *temp_head, *temp_tail, *dummy, *dummy_tail;

	int indexFirstNode, indexSecondNode, index = 1,
		substract, length;
	char flag = 'y', resume = 'n';

	if (myList != NULL)
	{
		indexFirstNodeBefore = myList->head;
		indexFirstNodeMiddle = myList->head; 
		indexFirstNodeAfter = myList->head;
		indexSecondNodeBefore = myList->head;
		indexSecondNodeMiddle = myList->head;
		indexSecondNodeAfter = myList->head;

		temp_head = myList->tail;
		temp_tail = myList->head;

		length = length_of_List(myList);

		// User Enter Index
		do
		{
			fprintf(stdout, "\n\n\t\tEnter an index first node : ");
			scanf("%d", &indexFirstNode);
			fprintf(stdout, "\n\t\tEnter an index second node : ");
			scanf("%d", &indexSecondNode);

			substract = indexSecondNode - indexFirstNode;

			printf("\n\n\t\tPrompt Continue(Y or N) : ");
			scanf("%c", &resume);


		}while(substract < 3 && length > 2 && resume == 'y');
		

		do 
		{
			// Swap Head and Tail Algorithm
			if (indexFirstNode == 1 && index == indexFirstNode)
			{
				dummy = myList->head->next;
				dummy->previous = NULL;

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

				temp_head->previous = NULL;
				temp_tail->next = NULL;

				myList->head = temp_head;
				myList->head->next = dummy;
				dummy->previous = myList->head;

				myList->tail = temp_tail;
				myList->tail->next = NULL;
				myList->tail->previous = dummy_tail;
				dummy_tail->next = myList->tail;

				flag = 'n';
			}

			// Swap other node algorithm
			if (index == indexFirstNode && indexSecondNode != length)
			{
				indexFirstNodeBefore = indexFirstNodeBefore->previous;
				indexFirstNodeAfter = indexFirstNodeAfter->next;
			}

			if (index == indexSecondNode)
			{
				indexSecondNodeBefore = indexSecondNodeBefore->previous;
				indexSecondNodeAfter = indexSecondNodeAfter->next;

				// Starting swap algorithm 
				indexFirstNodeBefore->next = indexSecondNodeMiddle;
				indexSecondNodeMiddle->previous = indexFirstNodeBefore;
				
				indexSecondNodeAfter->previous = NULL;

				indexSecondNodeMiddle->next = indexFirstNodeAfter;
				indexFirstNodeAfter->previous = indexSecondNodeMiddle;

				indexSecondNodeBefore->next = indexFirstNodeMiddle;
				indexFirstNodeMiddle->previous = indexSecondNodeBefore;
				indexFirstNodeMiddle->next = indexSecondNodeAfter;

				flag = 'n';
			}

			// Traversal throught the list
			if (index != indexFirstNode && index < indexFirstNode)
			{
				indexFirstNodeBefore = indexFirstNodeBefore->next;
				indexFirstNodeMiddle = indexFirstNodeMiddle->next;
				indexFirstNodeAfter = indexFirstNodeAfter->next;
			}
			
			if (index != indexSecondNode && index < indexSecondNode)
			{
				indexSecondNodeBefore = indexSecondNodeBefore->next;
				indexSecondNodeMiddle = indexSecondNodeMiddle->next;
				indexSecondNodeAfter = indexSecondNodeAfter->next;
			}
			index++;
		}while(flag == 'y');
	}
	else
	{
		return myList;
	}

	fprintf(stdout, "\n\n\t\t  After swap list");
	display(myList);
	
	return myList;
}
// -------------------------------------------------------
void userInput(int *numberptr, struct node *node)
{
	int number;
	
	fflush(stdin);
	printf("\n\t\t\tEnter Customer Name : ");
	gets(node->customerName);

	fflush(stdin);
	printf("\n\t\t\tEnter Customer Number : ");
	fflush(stdin);
	scanf("%d", &number);

	fflush(stdin);
	printf("\n\t\t\tEnter Transaction description : ");
	gets(node->transactionDescription);

	*numberptr = number;
}
// -------------------------------------------------------
void display(const struct LList * myList)
{
	struct node *traversal;
	int length;
	
	printf("\n\n\n");

	myList = myList;
	if (myList != NULL)
	{
//		if (myList->head != NULL && myList->head->value != NULL)
		{
			traversal = myList->head;

			printf("\n\n");
			length = 1;
			while(traversal != NULL)
			{
			
				printf("\t\t\tNode %d of List ", length);
				printf("\n\n\t\t\tCustomer Name : ");
				puts(traversal->customerName);
			
				printf("\t\t\tCustomer Number : %d", traversal->customerNumber);
				printf("\n\t\t\tTrasaction Description : "); 
				puts(traversal->transactionDescription);

				printf("\n");
				traversal = traversal->next;
				length++;
			}
		}
	}
	else
	{
		exit(0);
	}	
	myList = myList;
}
// -------------------------------------------------------
int length_of_List(struct LList *myList)
{
	struct node *traversal;
	int length = 1;
	
	if (myList != NULL)
	{
		traversal = myList->head;

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

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

	return length;
}
// -------------------------------------------------------
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 count_specific_value(struct LList *myList)
{
	struct node *traversal;
	char nameCustomer[20];
	int length = 1;
	int value, number = 0;

	if (myList != NULL)
	{
		fprintf(stdout, "\nt\t\tEnter a Customer Name to count : ");
		gets(nameCustomer);

		fprintf(stdout, "\n\t\tEnter a Customer Number to count : ");
		scanf("%d", &value);

		traversal = myList->head;

		length = 1;
		while (traversal != NULL)
		{
			if (value == traversal->customerNumber
				&& nameCustomer == traversal->customerName)
			{
				number++;
			}
			traversal = traversal->next;
			length++;
		}
		fprintf(stdout, "\n\n\t\t\tValue %d has exist %d times in list\n", value, number);
	}
	else
	{
		exit(0);
	}

	/*
		Traversal a list required O(n) linear time
		where 5 node in list consumed O(5)
	*/
	return number;
}
// --------------------------------------------------------
int get_Value_at_index(struct LList *myList)
{
	struct node *traversal;

	int length = 1, index, value, real_length;
	
	if (myList != NULL)
	{
		traversal = myList->head;

		do
		{
			fprintf(stdout, "\n\n\tEnter an index to retrieve a Customer Name, Customer Number and Transaction : ");
			scanf("%d", &index);

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

		length = 1;
		while (traversal->next != NULL && index >= length)
		{
			if (index == length )
			{
				value = traversal->customerNumber;
			}

			traversal = traversal->next;
			length++;
		}
	
		value = traversal->customerNumber;
		fprintf(stdout, "\n\n\tCustomer Information at node %d of list ", index);
		printf("\n\n\t\t\tCustomer Name :");
		puts(traversal->customerName);

		printf("\n\t\t\tCustomer Number : ");
		printf("%d", traversal->customerNumber);

		printf("\n\t\t\tTransaction description ");
		puts(traversal->transactionDescription);
	}
	else
	{
		exit(0);
	}

	return value;
}
// -------------------------------------------------------
int Middle_of_List(struct LList *myList)
{
	int middle, length, temp_length;
	float remainder;

	if (myList != NULL)
	{
		length = length_of_List(myList);

		if (length % 2 != 0)
		{
			temp_length = length % 2;
			remainder = (float)temp_length;
			if (remainder >= 0.5)
			{
				middle = (length / 2) + 1;
				fprintf(stdout, "\n\n\t\tMiddle of Link List is at index %d", middle);
			}
			else
			{
				middle = length / 2;
				fprintf(stdout, "\n\n\t\tMiddle of Link List is at index %d", middle);
			}
		}
		else
		{
			middle = length / 2;
			fprintf(stdout, "\n\n\t\tMiddle of Link List is at index %d", middle);
		}
	}
	else
	{
		exit(0);
	}

	return middle;
}
// -------------------------------------------------------
void BinarySearch(struct LList *myList)
{
	struct LList *left, *right;

	struct node *traversal_left, 
		*traversal_right, *traversal;
	int length, middle, searchNumber;
	

	left = (struct LList *)malloc(sizeof(struct LList));
	assert(left != 0);

	right = (struct LList *)malloc(sizeof(struct LList));
	assert(right != 0);

	length = length_of_List(myList);
	middle = Middle_of_List(myList);

	myList = MergeSort(myList, length);
	myList = myList;

	fprintf(stdout, "\n\n\t\tEnter a customer number to search : ");
	scanf("%d", &searchNumber);

	if (length == 1)
	{
		fprintf(stdout, "\n\n\t\t\tResult of search is %d at index %d", myList->head, length);
	}
	
	left->head = myList->head;
	
	// To mark a middle of a list
	traversal = myList->head;

	// To get middle of a list
	length = 1;
	while(length<=middle)
	{
		traversal = traversal->next;
		length++;
	}
	// To identify right head and left tail
	right->head = traversal;
	traversal_right = right->head;
	left->tail = traversal->previous;
	left->tail->next = NULL;

	while(traversal_right->next != NULL)
	{
		traversal_right  = traversal_right->next; 
	}
	right->tail = traversal_right;


	traversal_right = right->head;
	traversal_left = left->head;

	if (searchNumber < traversal->customerNumber)
	{
		length = 1;
		while(traversal_left != NULL)
		{
			if (traversal_left->customerNumber == searchNumber)
			{
				printf("\n\n\t\tResult of search is %d and its index is %d", traversal_left->customerNumber, length);
			}
			traversal_left = traversal_left->next;
			length++;
		}
	}
	else
	{
		length = 1;
		while(traversal_right != NULL)
		{
			if (traversal_right->customerNumber == searchNumber)
			{
				printf("\n\n\t\tResult of search is %d and its index is %d", traversal_right->customerNumber, length);
			}
			traversal_right = traversal_right->next;
			length++;
		}
	}
	
	left->tail->next = right->head;

	free(left);
	free(right);	
}
// -------------------------------------------------------
void BiDirectionSearch(struct LList *myList)
{
	struct node *frontTraversal;
	struct node *backTraversal;
	int searchKey;

	if (myList != NULL)
	{
		frontTraversal = myList->head;
		backTraversal = myList->tail;

		printf("\n\n\t\tEnter Customer Number to search : ");
		scanf("%d", &searchKey);
		
		/*
			An if or while expression is not
			evaluted if first two expression is true
			Therefore, this is recommended to 
			minimize expression in a if and while
		*/
		while(frontTraversal != backTraversal
			&& frontTraversal->customerNumber != searchKey
			&& backTraversal->customerNumber != searchKey)
		{
			frontTraversal = frontTraversal->next;
			backTraversal = backTraversal->previous;
		}
	}
	else
	{
		exit(0);
	}

	if (frontTraversal->customerNumber == searchKey)
	{
		fprintf(stdout, "\n\n\t\t\tResult of Searched : %d", frontTraversal->customerNumber);
	}
	else
	{
		fprintf(stdout, "\n\n\t\t\tResult of Searched : %d", backTraversal->customerNumber);	
	}
}
// -------------------------------------------------------
void RangeSearch(struct LList *myList)
{
	struct node *firstTraversal, *secondTraversal;
	int firstRange, secondRange, length;

	/* 
		This algorithm must sorted before it can perform 
		searching
	*/
	if (myList != NULL)
	{
		length = length_of_List(myList);
		myList = MergeSort(myList, length);

		printf("\n\n\t\t\tEnter two customer range number : ");
		
		do
		{
			printf("\n\t\tEnter First Customer Number : ");
			scanf("%d", &firstRange);
		
			printf("\n\t\tEnter Second Customer Number : ");
			scanf("%d", &secondRange);
			
		}while(firstRange >= secondRange);

		firstTraversal = myList->head;
		secondTraversal = myList->head;

		// To search a range specify by user
		while(secondTraversal->customerNumber 
			!= secondRange)
		{
			if (firstTraversal->customerNumber != firstRange)
			{
				firstTraversal = firstTraversal->next;
			}

			if (secondTraversal->customerNumber != secondRange)
			{
				secondTraversal = secondTraversal->next;
			}
		}

		printf("\n\n");
		// To print customer range
		while(firstTraversal != secondTraversal->next)
		{
			printf("\n\t\t\tCustomer Name : ");
			puts(firstTraversal->customerName);

			printf("\t\t\tCustomer Number : %d", firstTraversal->customerNumber);

			printf("\n\t\t\tTrasaction Description : "); 
			puts(firstTraversal->transactionDescription);
			
			firstTraversal = firstTraversal->next;
		}

		myList = myList;


	}
	else
	{
		exit(0);
	}
	/*
		Prompt user input is not a good design which 
		violate priciples of API
	*/	
}
// -------------------------------------------------------
int Main_menu()
{
	int choice;

	fprintf(stdout, "\n\n\n\t\t\t  Main Menu");
	fprintf(stdout,	"\n\n\n\t\t     1. Double Link List");
	fprintf(stdout,	"\n\t\t     2. Order Double Link List");
	fprintf(stdout,	"\n\t\t     3. Skip List");
	fprintf(stdout,	"\n\t\t     4. Adjacency List");
	fprintf(stdout,	"\n\t\t     5. Binary Search Tree\n\n\t\t\t Enter a choice : ");
	
	scanf("%d", &choice); 

	return choice;
}
// --------------------------------------------------------
int DLL_Function()
{
	int choice;


	fprintf(stdout, "\n\n\t\t    Double Link List Function\n"); 

	fprintf(stdout, "\n\n\n\t\t\t1. List allocate\n\t\t\t2. Node Allocate");
	fprintf(stdout, "\n\t\t\t3. User Input\n\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t5. Insert Behind\n\t\t\t6. Insert Front");
	fprintf(stdout, "\n\t\t\t7. Random Insert\n\t\t\t8. Remove Behind");
	fprintf(stdout, "\n\t\t\t9. Remove Front\n\t\t\t10. Random Remove");
	fprintf(stdout, "\n\t\t\t11. Remove Duplicates\n\t\t\t12. Merge List");
	fprintf(stdout, "\n\t\t\t13. Swap Node\n\t\t\t14. Split List");
	fprintf(stdout, "\n\t\t\t15. Count Value\n\t\t\t16. Get Value");
	fprintf(stdout, "\n\t\t\t17. Sorting\n\t\t\t18. Searching");
	fprintf(stdout, "\n\t\t\t19. Middle\n\t\t\t20. Length");
	fprintf(stdout, "\n\t\t\t21. Interwine\n\t\t\t22. Reverse List");
	fprintf(stdout, "\n\t\t\t23. Display\n\t\t\t24. List Deallocate");
	fprintf(stdout, "\n\t\t\t25. Switch Number List\n\t\t\t");

	fprintf(stdout, "\n\n\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
}
// --------------------------------------------------------
int ODCLL_Function()
{
	int choice;

	fprintf(stdout, "\n\n\t\tOrder Double Link List Function\n");
	
	fprintf(stdout, "\n\n\n\t\t\t1. List allocate\n\t\t\t2. Node Allocate");
	fprintf(stdout, "\n\t\t\t3. User Input\n\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t5. Sorted Insert\n\t\t\t6. Remove Behind");
	fprintf(stdout, "\n\t\t\t7. Display\n\t\t\t8. List Deallocate");

	fprintf(stdout, "\n\n\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
}
// -------------------------------------------------------
int SL_Function()
{
	int choice;

	fprintf(stdout, "\n\n\t\t\tSkip List Function\n");
	
	fprintf(stdout, "\n\n\n\t\t\t1. List allocate\n\t\t\t2. Node Allocate");
	fprintf(stdout, "\n\t\t\t3. User Input\n\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t5. Sorted Insert\n\t\t\t6. Remove Behind");
	fprintf(stdout, "\n\t\t\t7. Skip List Searching");

	fprintf(stdout, "\n\n\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
	/* [url]http://www.csee.umbc.edu/courses/undergraduate/341/fall01/Lectures/SkipLists/skip_lists/skip_lists.html[/url]
	   [url]http://256.com/sources/skip/docs/skipLists.c[/url]
	   [url]http://en.literateprograms.org/Skip_list_(C[/url])
	   [url]http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_skip.aspx[/url]
	   [url]http://algolist.manual.ru/ds/[/url]

	*/
}
// ----------------------------------------------------------
int BST_Function()
{
	int choice;
	
	fprintf(stdout, "\n\n\t\t     Binary Search Tree Function\n");
	
	fprintf(stdout, "\n\n\n\t\t\t1. Binary Search Tree allocate\n\t\t\t2. Tree Node Allocate");
	fprintf(stdout, "\n\t\t\t3. User Input\n\t\t\t4. Initialize Node");
	fprintf(stdout, "\n\t\t\t5. Insert\n\t\t\t6. Remove");
	fprintf(stdout, "\n\t\t\t7. BST Searching\n\t\t\t8. Display");
	fprintf(stdout, "\n\t\t\t9. Minimum\n\t\t\t10. Maximum");
	fprintf(stdout, "\n\t\t\t11. BST Deallocate\n\t\t\t");

	fprintf(stdout, "\n\n\t\t\tEnter a choice : ");
	scanf("%d", &choice);

	return choice;
}
// -------------------------------------------------------



#ifndef _LList_
#define _LList_

// Single Node
struct node
{
	char customerName[20];
	int customerNumber;
	char transactionDescription[30];

	struct node *next;   // A node is 4 byte 
	struct node *previous; // 4+4+20+30+4 = 62 + 2 =64
};


// Consists of many nodes as a Link List
struct LList
{
	struct node *head;
	struct node *tail;
};

	
// Add index to struct

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

int number_list();

struct LList* list_allocate(struct LList *);
int* list_deallocate(struct LList *, int *);

void Initialize_List(struct LList *);

struct LList* InsertBehind(struct LList *, struct node *);
struct LList* InsertFront(struct LList *, struct node*);
struct LList* RandomInsert(struct LList *, struct node*);

struct LList* SortedInsert(struct LList *, struct node *);

struct LList* RemoveBehind(struct LList *);
struct LList* RemoveFront(struct LList *);
struct LList* RandomRemove(struct LList *);
struct LList* RemoveDuplicates(struct LList *);

struct LList* ReverseList(struct LList *);
struct LList* MergeList(struct LList *, struct LList *);
struct LList* MergeSort(struct LList *, int);
struct LList* Merge(struct LList *, struct LList *);

struct LList* Interwine(struct LList *, struct LList *);

void SplitList(struct LList *);
void AISplitList(struct LList *);
void UserSplitList(struct LList *);


int LList_ValidateIsAlloc(struct LList *); 

struct LList* SwapNode(struct LList *);
 
// --------------------Node Function----------------------

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

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


// ------------------Utility Function--------------------

void draw();

void userInput(int *, struct node *);
void display(const struct LList *);
int length_of_List(struct LList *); 
int Validate_Index(struct LList *, int); 
int count_specific_value(struct LList *);
int get_Value_at_index(struct LList *);
int Middle_of_List(struct LList *); 

void BinarySearch(struct LList *);
void BiDirectionSearch(struct LList *);
void RangeSearch(struct LList *);


int Main_menu();
int DLL_Function();
int ODCLL_Function();
int SL_Function();
int AL_Function();
int BST_Function();

#endif


#ifndef _BST_
#define _BST_
 
struct Tree_Node 
{
    int value;
    struct Tree_Node *leftNode;
    struct Tree_Node *rightNode;
};
 
struct BST
{
    struct Tree_Node *root;
};

// -----------------Tree Node Function---------------------------
struct Tree_Node* Tree_Node_Allocate(struct Tree_Node *);
void Tree_Node_Deallocate(struct Tree_Node *);
 
struct Tree_Node* Tree_Node_Initialize(struct Tree_Node *, int *);
 
struct Tree_Node* Searching(struct BST *, int *);
struct Tree_Node* RecursiveSearch(struct Tree_Node *, int *, ...);
struct Tree_Node* RecursiveMinSearch(struct Tree_Node *);
struct Tree_Node* RecursiveMaxSearch(struct Tree_Node *);

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

// ------------------BST Tree Function---------------------------
struct BST* BST_Allocate(struct BST *);
int* BST_Deallocate(struct BST *, int *);
 
struct BST* BST_Insert(struct BST *, struct Tree_Node *);
struct BST* BST_Remove(struct BST *,int *); 

void FindMin(struct BST *);
void FindMax(struct BST *);
void MinHeight(int *);
void MaxHeight(int *);

void BST_UserInput(int *);
int* QuerySearchValue(int *);
int* numberTreeNodes(int *);
int* removeNode(int *);

// Root->Left->Right
/*
	If left node has children, traversal down until left
	has no children
	Or called Depth-First Traversal(DFS)
*/
void PreorderDisplay(struct BST *);  
void RecursivePreorderDisplay(struct Tree_Node *);

// Left->Root->Right
void InorderDisplay(struct BST *);
void RecursiveInorderDisplay(struct Tree_Node *);

// Left->Right->Root
void PostorderDisplay(struct BST *);
void RecursivePostorderDisplay(struct Tree_Node *);
/*
	Breadth-first traversal(BFS) - traversal from level 0 
	until lowest level
*/
void RecursivePostOrder_Deallocate(struct Tree_Node *);
void SearchDisplay(struct Tree_Node *, int *);

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

#endif
/*
	Binary Search Tree can be used for efficient searching, 
	arithmetic expression parsing, and 
	data compression

	Fullness - Previous Level * 2 = Current Level is 
			   consider fullness
	Balance - isBalanced() - Find Maximum height
	          of left node and right node
			  if == balanced else unbalaced
			  All node must same height then 
			  considered balanced
	Leftness - 

    Recursion good for keeping track of paths(Fixed Path or a route)

	AVL Tree - Tree that help balancing when inserted
	Splay Tree - Move data that frequent accessed to
				 the top of tree
    Heap - Another sorted tree structure used maily
	       in priority queue
	Huffman Tree - Used for data compression
    
*/



#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
 
#include "BST.h"
// --------------------------------------------------------------
/*
	Interpolation Search
	[url]http://www.brpreiss.com/books/opus4/html/page9.html[/url]
	[url]http://www.ccs.neu.edu/home/vkp/csu213-sp05/Assignments/Assignment5/[/url]
*/

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

struct BST* BST_Allocate(struct BST *BST)
{
    BST = malloc(sizeof(struct BST));
    assert(BST != 0);
    BST->root = NULL;
 
    return BST;
}
// -----------------------------------------------------------
int* BST_Deallocate(struct BST *BST, int *isBST_De_allocate)
{
	// Memory Leak if i only delete root and not
    // all tree nodes request from heap memory
	/*
		Use postorder traversal method to free Tree Node
		and finally root
	*/

    if (BST != NULL && BST->root != NULL)
    {
		if (*isBST_De_allocate == 0)
		{
			RecursivePostOrder_Deallocate(BST->root);
			free(BST);
		}
    }
    else
    {
        exit(0);
    }
	
	*isBST_De_allocate = 1;

	return isBST_De_allocate;
}
// --------------------------------------------------------
void RecursivePostOrder_Deallocate(struct Tree_Node *Tree_Node)
{
	if (Tree_Node != NULL)
	{
		RecursivePostOrder_Deallocate(Tree_Node->leftNode);
		RecursivePostOrder_Deallocate(Tree_Node->rightNode);
		free(Tree_Node);
	}
}
// ---------------------------------------------------------
struct BST* BST_Insert(struct BST *BST, struct Tree_Node *Tree_Node)
{
	struct Tree_Node *traversal;
	int *numberptr, number;

	numberptr = &number;

	traversal = BST->root;

	*numberptr = Tree_Node->value;

	if (BST->root == NULL)
	{
		BST->root = Tree_Node;
	}
	else
	{
		if (BST->root->leftNode == NULL 
			|| BST->root->rightNode == NULL)
		{
			if (Tree_Node->value < BST->root->value)
			{
				BST->root->leftNode = Tree_Node;
			}
			else
			{
				BST->root->rightNode = Tree_Node;
			}
		}
		else
		{
			traversal = Searching(BST, numberptr);
			if (*numberptr < traversal->value)
			{
				traversal->leftNode = Tree_Node;
			}
			else
			{
				traversal->rightNode = Tree_Node;
			}
		}
	}
	/*
		Top Down construction - Create root first
		Bottom Up construction - Create child first
	*/
	return BST;
}
// -------------------------------------------------------
struct BST* BST_Remove(struct BST *BST,int *removeptr)
{
	// Parent of RemoveNode
	struct Tree_Node *parent;      
	// Parent of traversal 
	struct Tree_Node *parent_traversal; 
	struct Tree_Node *tempTraversal;
	struct Tree_Node *traversal;    
	struct Tree_Node *RemoveNode;  
	// To maintain children of RemoveNode
	struct Tree_Node *tempRemoveNode;  

	char special = 'y';

	parent = BST->root;
	traversal = BST->root;
	tempTraversal = BST->root;
	parent_traversal = BST->root;

	/*
		if no child, just delete
		if one child, point by grandparent
		
		if two children, 
		swap with it with 
		inorder-successor(Left child of right sub Tree)	
		// Smallest in right sub tree
		Traverse once to right , then continue
		traverse to left  
		
		or
		inorder-predecessor(Right child of Left sub Tree)
		// Largest in left sub tree
	*/
	
	// Iteractve Remove Tree Node
	while(traversal != NULL)
	{
		// To remove root node
		if (*removeptr == tempTraversal->value)
		{
			RemoveNode = BST->root;
			tempRemoveNode = BST->root;
			
			// got 2 children
			if (RemoveNode->leftNode != NULL
						&& RemoveNode->rightNode != NULL)
			{
				// Traverse once to right tree 
				if (tempTraversal->rightNode != NULL)
				{
					tempTraversal = tempTraversal->rightNode;
				}

				// Continue traverse smallest unit left sub tree
				while(tempTraversal->leftNode != NULL)
				{
					tempTraversal = tempTraversal->leftNode;
				}
				tempRemoveNode->leftNode = RemoveNode->leftNode;
				tempRemoveNode->rightNode = RemoveNode->rightNode;

				tempTraversal->leftNode = tempRemoveNode->leftNode;
				tempTraversal->rightNode = tempRemoveNode->rightNode;

				if (traversal != NULL)
				{
					traversal = traversal->rightNode;
				}

				traversal->leftNode = NULL;
				Tree_Node_Deallocate(RemoveNode);

				BST->root = tempTraversal;

				while(traversal != NULL)
				{
					traversal = traversal->leftNode;
				}
			}		
		}
		else if (traversal != NULL)
		{
			if (*removeptr < traversal->value)
			{
				traversal = traversal->leftNode;
				parent_traversal = parent_traversal->leftNode;

				if (traversal != NULL)
				{
					RemoveNode = traversal;
					tempRemoveNode = traversal;
				}

				if (traversal != NULL)
				{
					if (traversal->value == *removeptr)
					{
						// got 2 children
						if (RemoveNode->leftNode != NULL
							&& RemoveNode->rightNode != NULL)
						{
							// Traverse once to right tree 
							if (traversal->rightNode != NULL)
							{
								traversal = traversal->rightNode;
								parent_traversal = parent_traversal->rightNode;
							}

							// Continue traverse smallest unit left sub tree
							while(traversal->leftNode != NULL)
							{
								traversal = traversal->leftNode;
							}

							// To identify parent of traversal
							if (parent_traversal->leftNode != NULL)
							{
								while(parent_traversal->leftNode->leftNode != NULL)
								{	
									parent_traversal = parent_traversal->leftNode;
								}
								special = 'n';
							}

							if (special == 'n')
							{
								tempRemoveNode->rightNode = RemoveNode->rightNode;
								tempRemoveNode->leftNode = RemoveNode->leftNode;
							}
							
							if (traversal->value 
								<parent->value)
							{
								parent->leftNode = traversal;
							}
							else
							{
								parent->rightNode = traversal;
							}

							if (special == 'n')
							{
								traversal->leftNode = tempRemoveNode->leftNode;
								traversal->rightNode = tempRemoveNode->rightNode;

								if (RemoveNode->value 
									< parent_traversal->value)
								{
									parent_traversal->leftNode = RemoveNode;
								}
								else
								{
									parent_traversal->rightNode = RemoveNode;
								}
							}
							else
							{
								traversal->leftNode = tempRemoveNode->leftNode;
							}
							Tree_Node_Deallocate(RemoveNode);
						}
						// Got 1 child
						else if (RemoveNode->leftNode != NULL
							|| RemoveNode->rightNode != NULL)
						{
							// Swap it with its Left child 
							if (RemoveNode->leftNode != NULL)
							{
								traversal = traversal->leftNode;
								
								if (traversal->value < parent->value)
								{
									parent->leftNode = traversal;
								}
								else
								{
									parent->rightNode = traversal;
								}
								Tree_Node_Deallocate(RemoveNode);
							}

							// Swap it with its Right child 
							if (RemoveNode->rightNode != NULL)
							{
								traversal = traversal->rightNode;

								if (traversal->value < parent->value)
								{
									parent->leftNode = traversal;
								}
								else
								{
									parent->rightNode = traversal;
								}
								Tree_Node_Deallocate(RemoveNode);
							}
						}
						// No child
						else
						{
							Tree_Node_Deallocate(RemoveNode);
							parent->leftNode = NULL;
						}
					}
				}
				if (parent != NULL)
				{
					parent = parent->leftNode;
				}	
			}
			else
			{
				traversal = traversal->rightNode;
				parent_traversal = parent_traversal->rightNode;
				
				if (traversal != NULL)
				{
					RemoveNode = traversal;
					tempRemoveNode = traversal;
				}

				if (traversal != NULL)
				{
					if (traversal->value == *removeptr)
					{
						// got 2 children
						if (RemoveNode->leftNode != NULL
							&& RemoveNode->rightNode != NULL)
						{
							// Traverse once to right tree 
							if (traversal->rightNode != NULL)
							{
								traversal = traversal->rightNode;
								parent_traversal = parent_traversal->rightNode;
							}

							// Continue traverse smallest unit left sub tree
							while(traversal->leftNode != NULL)
							{
								traversal = traversal->leftNode;
							}

							parent_traversal = parent_traversal;
							// To identify parent of traversal
							if (parent_traversal->leftNode != NULL)
							{
								while(parent_traversal->leftNode->leftNode != NULL)
								{
									parent_traversal = parent_traversal->leftNode;
								}
								special = 'n';
							}

							tempRemoveNode->leftNode = RemoveNode->leftNode;
							tempRemoveNode->rightNode = RemoveNode->rightNode;
							
							if (traversal->value 
								<parent->value)
							{
								parent->leftNode = traversal;
							}
							else
							{
								parent->rightNode = traversal;
							}
							
							if (special == 'n')
							{
								traversal->leftNode = tempRemoveNode->leftNode;
								traversal->rightNode = tempRemoveNode->rightNode;
						
								if (RemoveNode->value 
									< parent_traversal->value)
								{
									parent_traversal->leftNode = RemoveNode;
								}
								else
								{
									parent_traversal->rightNode = RemoveNode;
								}
							}
							else
							{
								traversal->leftNode = tempRemoveNode->leftNode;
							}
							Tree_Node_Deallocate(RemoveNode);
						}
						// Got 1 child
						else if (RemoveNode->leftNode != NULL
							|| RemoveNode->rightNode != NULL)
						{
							// Swap it with its Left child 
							if (RemoveNode->leftNode != NULL)
							{
								traversal = traversal->leftNode;
								
								if (traversal->value < parent->value)
								{
									parent->leftNode = traversal;
								}
								else
								{
									parent->rightNode = traversal;
								}
								Tree_Node_Deallocate(RemoveNode);
							}

							// Swap it with its Right child 
							if (RemoveNode->rightNode != NULL)
							{
								traversal = traversal->rightNode;

								if (traversal->value < parent->value)
								{
									parent->leftNode = traversal;
								}
								else
								{
									parent->rightNode = traversal;
								}
								Tree_Node_Deallocate(RemoveNode);
							}
						}
						// No child
						else
						{
							Tree_Node_Deallocate(RemoveNode);
							parent->rightNode = NULL;
						}
					}
				}
				if (parent != NULL)
				{
					parent = parent->rightNode;
				}
			}	
		}
	}
	
	return BST;
}
// -------------------------------------------------------
void FindMin(struct BST *BST)
{
	struct Tree_Node *Tree_Node;

	if (BST != NULL)
	{
		if (BST->root->leftNode != NULL)
		{
			Tree_Node = RecursiveMinSearch(BST->root->leftNode);
		}
	}
	else
	{
		exit(0);
	}
	printf("\n\n\t\tMinimum value of this tree : %d", Tree_Node->value);
}
// -------------------------------------------------------
void FindMax(struct BST *BST)
{
	struct Tree_Node *Tree_Node;

	if (BST->root != NULL)
	{
		if (BST->root->rightNode != NULL)
		{
			Tree_Node = RecursiveMaxSearch(BST->root->rightNode);
		}
	}
	else
	{
		exit(0);
	}
	printf("\n\n\t\tMaximum value of this tree : %d", Tree_Node->value);
}
// -------------------------------------------------------
void MinHeight(int *numberNodesptr)
{
	if (*numberNodesptr != 0)
	{
		// n = 2 ^ h;
	}
	else
	{
		exit(0);
	}
}
// --------------------------------------------------------
void MaxHeight(int *numberNodesptr)
{
	if (*numberNodesptr != 0)
	{
		printf("\n\n\t\t\tMax Height of Tree : %d", *numberNodesptr); 
	}
	else
	{
		exit(0);
	}
}
// -------------------------------------------------------
void PreorderDisplay(struct BST *BST)
{
	// Root->Left->Right
	
	printf("\n\n\n\n\t\t    Preorder Traversal Display\n");

	if (BST->root != NULL)
	{
		RecursivePreorderDisplay(BST->root);
	}
	else
	{
		exit(0);
	}
}
// -------------------------------------------------------
void RecursivePreorderDisplay(struct Tree_Node *Tree_Node)
{
	// Root->Left->Right
	if (Tree_Node != NULL)
	{
		printf("\n\t\t\tValue of node : %d", Tree_Node->value);
		if (Tree_Node->leftNode != NULL)
		{
			RecursivePreorderDisplay(Tree_Node->leftNode);
		}

		if (Tree_Node->rightNode != NULL)
		{
			RecursivePreorderDisplay(Tree_Node->rightNode);
		}
	}
	else
	{
		exit(0);
	}
}

// -------------------------------------------------------
void InorderDisplay(struct BST *BST)
{
	// Left->Root->Right

	printf("\n\n\n\n\t\t    Inorder Traversal Display\n");

	if (BST->root != NULL)
	{
		RecursiveInorderDisplay(BST->root);	
	}
	else
	{
		exit(0);
	}
}
// -----------------------------------------------------
void RecursiveInorderDisplay(struct Tree_Node *Tree_Node)
{
	if (Tree_Node != NULL)
	{
		if (Tree_Node->leftNode != NULL)
		{
			RecursiveInorderDisplay(Tree_Node->leftNode);
		}

		printf("\n\t\t\tValue of node : %d", Tree_Node->value);
		
		if (Tree_Node->rightNode != NULL)
		{
			RecursiveInorderDisplay(Tree_Node->rightNode);
		}
	}
	else
	{
		exit(0);
	}
	/*
		1. First call left-node 
		2. After finished calling, return to point where its 
		   calling from which is root 
		   Display root value
        3. Call right node

        After finished calling itself, return to 
		previous stack where its calling from
		
    */
}
// -----------------------------------------------------
void PostorderDisplay(struct BST *BST)
{
	// Left->Right->Root

	printf("\n\n\n\n\t\t    Postorder Traversal Display\n");
	if (BST->root != NULL)
	{
		RecursivePostorderDisplay(BST->root);
	}
	else
	{
		exit(0);
	}

	printf("\n\n\n");
}
// -------------------------------------------------------
void RecursivePostorderDisplay(struct Tree_Node *Tree_Node)
{
	if (Tree_Node != NULL)
	{
		if (Tree_Node->leftNode != NULL)
		{
			RecursivePostorderDisplay(Tree_Node->leftNode);
		}

		if (Tree_Node->rightNode != NULL)
		{
			RecursivePostorderDisplay(Tree_Node->rightNode);
		}

		printf("\n\t\t\tValue of node : %d", Tree_Node->value);
	}
	else
	{
		exit(0);
	}
}
// ------------------------------------------------------
void SearchDisplay(struct Tree_Node *Tree_Node, int *resultSearched)
{
	if (Tree_Node != NULL)
	{
		if (Tree_Node->value == *resultSearched)
		{
			printf("\n\n\t\t\tResult of searched : %d\n", Tree_Node->value);
		}
		else
		{
			printf("\n\n\t\tSearch Not Found\n");
		}
	}
	else
	{
		exit(0);
	}
}
// ------------------------------------------------------
struct Tree_Node* Searching(struct BST *BST, int *numberptr)
{
    if (BST != NULL)
    {
		return RecursiveSearch(BST->root, numberptr);
    }
    else
    {
        exit(0);
    }
}
// -----------------------------------------------------
struct Tree_Node* RecursiveSearch(struct Tree_Node *Tree_Node
								  , int *numberptr, ...)
{
	struct Tree_Node* result;

	result = Tree_Node;

	if (Tree_Node != NULL)
	{
		if (Tree_Node->value == *numberptr)
		{
			return result;
		}
		else
		{
			if (Tree_Node->leftNode != NULL 
				|| Tree_Node->rightNode != NULL)
			{
				if (*numberptr < Tree_Node->value)
				{
					if (Tree_Node->leftNode != NULL)
					{
						return RecursiveSearch(Tree_Node->leftNode, numberptr);
					}
				}
				else
				{
					if (Tree_Node->rightNode != NULL)
					{
						return RecursiveSearch(Tree_Node->rightNode, numberptr);
					}
				}
			}
		}
	}
	return result;
}
// -----------------------------------------------------
struct Tree_Node* RecursiveMinSearch(struct Tree_Node *Tree_Node)
{
	if (Tree_Node != NULL)
	{
		if (Tree_Node->leftNode != NULL)
		{
			Tree_Node =  RecursiveMinSearch(Tree_Node->leftNode);
		}
	}
	return Tree_Node;
}
// ------------------------------------------------------
struct Tree_Node* RecursiveMaxSearch(struct Tree_Node *Tree_Node)
{
	if (Tree_Node != NULL)
	{
		if (Tree_Node->rightNode != NULL)
		{
			Tree_Node = RecursiveMaxSearch(Tree_Node->rightNode);
		}
	}
	else
	{
		exit(0);
	}
	return Tree_Node;
}
// ------------------------------------------------------
void BST_UserInput(int *numberptr)
{
    int value;

    printf("\n\n\t\t\tEnter a value : ");
    scanf("%d", &value);
 
    *numberptr = value;
}
// ------------------------------------------------------
int* QuerySearchValue(int *numberptr)
{
	int value;

	printf("\n\n\t\t\tEnter a value to search : ");
	scanf("%d", &value);

	*numberptr = value;
	return numberptr;
}
// -----------------------------------------------------
struct Tree_Node* Tree_Node_Allocate(struct Tree_Node *Tree_Node)
{
    Tree_Node = malloc(sizeof(struct Tree_Node));
    assert(Tree_Node != 0);

    Tree_Node->leftNode = NULL;
    Tree_Node->rightNode = NULL;
 
    return Tree_Node; 
}
// ------------------------------------------------------
void Tree_Node_Deallocate(struct Tree_Node *Tree_Node)
{
    if (Tree_Node != NULL)
    {
        free(Tree_Node);
        Tree_Node->leftNode = NULL;
        Tree_Node->rightNode = NULL;
    }
    else
    {
        exit(0);
    }
}
// -------------------------------------------------------
struct Tree_Node* Tree_Node_Initialize(struct Tree_Node *Tree_Node,
                                     int *numberptr)
{
    if (Tree_Node != NULL)
    {
        Tree_Node->value = *numberptr;
		Tree_Node->leftNode = NULL;
		Tree_Node->rightNode = NULL;
    }
    else
    {
        exit(0);
    }
 
    return Tree_Node;
}
// -------------------------------------------------------
int* numberTreeNodes(int *numberNodesptr)
{
	printf("\n\n\t\t\tEnter Number of Nodes : ");
	scanf("%d", &numberNodesptr);

	return numberNodesptr;
}
// -------------------------------------------------------
int* removeNode(int *removeptr)
{
	printf("\n\n\t\t\tEnter a value to remove : ");
	scanf("%d", removeptr);
	/*
		If pointer or array, no need address operator
	*/

	return removeptr;
}
// --------------------------------------------------------

I hope this help others.
  #33  
Old 12-Jun-2008, 08:52
kalyan kalyan is offline
New Member
 
Join Date: Jun 2008
Posts: 1
kalyan is on a distinguished road

Re: Link List In C


Hey cn u tell me what is mean by return of value in c
  #34  
Old 12-Jun-2008, 14:33
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Link List In C


Quote:
Originally Posted by kalyan
Hey cn u tell me what is mean by return of value in c
Please clarify. Your question is incomprehensible.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
game problem using linkedListType.h and random function eureka360 C++ Forum 5 16-Feb-2007 11:48
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 13:31
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
linked list error message Krandygrl00 C++ Forum 4 22-Jun-2005 15:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.