且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

考虑到时间复杂度和空间复杂性,我想回顾一下我的代码是否足够好?

更新时间:2023-02-05 22:54:30

while(no_of_nodes>0)
{
    if(no_of_nodes>=1)
    {


if子句是多余的,因为如果no_of_nodes小于1,则循环将无法继续.

另外,创建节点时,应将其初始化,以使p->next为NULL.仅当在链中添加下一个节点时,才应将新节点的地址设置为p->next


The if clause is redundant as the loop cannot continue if no_of_nodes is less than 1.

Also, when you create a node you should initialise it such that p->next is NULL. Only when you add the next node in the chain should you set the address of the new one into p->next