Linked list sorting in C

前端 未结 5 742
自闭症患者
自闭症患者 2021-01-25 06:48

I\'m writing a simple file for one of my classes that is a simple linked list activity and I need to sort a linked list.

This is my source code so far:

/         


        
5条回答
  •  时光说笑
    2021-01-25 07:53

    Well, This loop will only go once (in the good case):

     while(tmpNxt != tmpPtr && tmpNxt->value < a){
            tmp = a;
            tmpPtr->value = tmpNxt->value;
            tmpNxt->value = tmp;
            tmpPtr = tmpPtr->next;
        }
    

    Since it's homework, just a hint: which is tmpNxt and which is tmpPtr after the first iteration?

    another lines to look at are those:

    tmpPtr = head;
    tmpNxt = tmpNxt->next;
    

    both examples explain why only the first two elements were replaced in your example.

提交回复
热议问题