F How to create circular header linked list by using function? | CodeTheta

January 09, 2014

,after that node insertion and displaythe list then the main function will call.if you get any compilation error please do comment in below of this post.

```/* create circular header linked list by using function */
/* http://native-code.blogspot.com */

# include <stdio.h>
# include <malloc.h>

{
int info;
};

int i; /* Represents number of nodes in the list */
int number;

/* http://native-code.blogspot.com */

{
char ch;

node = start;      /* Point to the header node in the list */
i = 0;
printf("\n Input choice n for break: ");
ch = getchar();
while(ch != 'n')
{
node = node->next;
printf("\n Input the node: %d:", (i+1));
scanf("%d", &node->info);
fflush(stdin);
printf("\n Input choice n for break: ");
ch = getchar();
i++;
}
printf("\n Total nodes = %d", i);
node = start;
node->info = i; /* Assign total number of nodes to the header node */
}

/* http://native-code.blogspot.com */

{
int count = node->info;
int node_number = 0;
int insert_node;

node = start;
node = node->next;

printf("\n Input node number you want to insert: ");
printf("\n Value should be less are equal to the");
printf("\n number of nodes in the list: ");
scanf("%d", &insert_node);

while(count)
{
if((node_number+1) == insert_node)
{
new1->next = node->next ;
node->next = new1;
printf("\n Input the node value: ");
scanf("%d", &new1->info);
node = node->next;
count--;
}
else
{
node = node->next;
count--;
}
node_number ++;
}
if (count == 0)
{
node = start;  /* Points to header node */
node->info = node->info+1;
}
}

/* Display the list */
/* http://native-code.blogspot.com */

{
int count = node->info;

node = start;
node = node->next;

while (count-1)
{
printf("\n 0x%x", node);
printf(" %d ", node->info);
node = node->next;
count --;
}
}

/* Function main */
/* http://native-code.blogspot.com */

void main()
{
create_circular_list(node);
printf("\n Before inserting a node list is as follows:\n");
display(node);
insertion(node);
printf("\n After inserting a node list is as follows:\n");
display(node);
}
/* http://native-code.blogspot.com */```