In addition to what others have said, there are a few other things that should be corrected.
Code:
/* Inserting Last */
Node *insertNode(Node*head,int value){
Node*newNode=(Node*)malloc(sizeof(Node));
You should check malloc() for NULL.
Code:
/* Inserting in the First */
Node* insertFirst(Node*head,int value){
Node*newNode=(Node*)malloc(sizeof(Node));
Again, check malloc() for NULL.
In the function
Code:
Node*insertSorted(Node*head,int value)
I would venture to say that you want to return head.
On a side note, I would have just made a seperate function to make the nodes.
Maybe something like
Code:
n_type *l_make(size_t count)
{
n_type *node, *list;
list = count ? malloc(sizeof *list) : NULL;
if (list != NULL) {
node = list;
while (--count != 0) {
node -> NEXT = malloc(sizeof *node -> NEXT);
if (node -> NEXT == NULL) {
l_free(list);
return NULL;
} else {
node = node -> NEXT;
}
}
node -> NEXT = NULL;
}
return list;
}
Then when I sort
Code:
n_type *n_sort(n_type *list, size_t count)
{
size_t half, other_half;
n_type *head, *tail, *sorted, **node;
if (count > 1) {
head = list;
other_half = half = count / 2;
while (--other_half != 0) {
head = head -> NEXT;
}
tail = head -> NEXT;
head -> NEXT = NULL;
tail = n_sort(tail, count - half);
head = n_sort(list, half);
node = GT(head, tail) ? &tail : &head;
sorted = list = *node;
*node = sorted -> NEXT;
while (*node != NULL) {
node = GT(head, tail) ? &tail : &head;
sorted = sorted -> NEXT = *node;
*node = sorted -> NEXT;
}
sorted -> NEXT = head != NULL ? head : tail;
}
return list;
}
Of course this is just my biased opinion on the whole thing.