Design: tail
is not needed
Present function set has no benefit from the tail
member. It is removable.
Bug: Wrong allocation size
Code allocates enough for a pointer rather than enough for the struct
.
Cast not needed. Better to allocate to the de-referenced object than type.
// node temp=(node)malloc(sizeof(node));
node temp = malloc(sizeof *node);
Function declarations say nothing about signature
void foo();
allows later calls like foo(1), foo("hello", 5.0)
to pass undetected as errors.
// void delete_front();
// void count();
// void display();
// void delete_last();
void delete_front(void);
void count(void);
void display(void);
void delete_last(void);
Inconsistent spacing
Use an auto-formatter - life is too short for manual formatting.
Lack of error checking
No checking if scanf("%d",&choice);
succeeded, nor malloc()
.
Unneeded code
temp=NULL;
serves nor purpose in node_add(int x)
Bug: de-referencing of NULL
delete_front()
does not check if head == NULL
before head->link
. tail
is not updated to NULL
when last link deleted.
Bug: de-referencing of NULL
delete_last()
does not check if p->link == NULL
before p->link->link
. Also expect head
to be updated to NULL
if last node deleted.