There is no errors or warnings and there are no problems in the main. this function supposed to get a sorted array and its size and to return a node which contains at the first size/2 indexes (size is the size of the array) numbers from the bigger to the smaller and then up to size/2 should put numbers from the smaller to the bigger. I strongly believe the problem isn't in the concept whereas it is in my understanding of how structures/nodes work.
typedef struct cell *CellPtr;
typedef struct cell{
int num;
CellPtr next;
CellPtr prev;
}Cell;
void fill_node(CellPtr *head, int array[], int size)
{
CellPtr finally;
int i;
if((finally=(CellPtr)malloc(sizeof(Cell)))==NULL)
{
printf("Allocation Error\n");
exit(1);
}
for(i=size-1; i>=size/2; i--)
{
if((finally->next=(CellPtr)malloc(sizeof(Cell)))==NULL)
{
printf("Allocation Error\n");
exit(1);
}
finally->num=array[i];
finally=finally->next;
}
for(i=0; i<size/2; i++)
{
if((finally->next=(CellPtr)malloc(sizeof(Cell)))==NULL)
{
printf("Allocation Error\n");
exit(1);
}
finally->num=array[i];
finally=finally->next;
}
finally->next=NULL;
*head=finally;
return;
}