I like Serena
Science Advisor
Homework Helper
MHB
- 16,335
- 258
evinda said:So, do I have to do it like that? (Thinking)
Code:Insertion Sort (NODE *A){ int key, i, j=2; while (A.next != NULL){ key=Nth(A,j).data; i=j-1; while(i>0 && Nth(A,i).data>key){ P = Nth(A, i-1); Q = Nth(A, i); R = Nth(A, i+1); i=i-1; } P.next = R; Q.next = R.next; R.next = Q; P.data=key; A.next=A.next.next; j++; } return A; }
Something like that... (Sweating)
What happens if you apply this algorithm to the list in your OP? (Wondering)