سؤال

I have some pseudo-code that I am trying to label. Here it is:

a= head
while a.value < b.value do a = a.next
b.next = a.next
a.next = b

To me this appears to be code used on a singly, or doubly linked list, but I have at least confirmed that it is NOT as doubly linked list. Does anyone know what data structure this would be from or act upon? Thank you.

هل كانت مفيدة؟

المحلول

It's for a singly-linked list. It looks like a routine to insert a node b into a list in sorted order. The chain of next links and lack of prev links are highly indicative of a singly-linked list. If this routine does what I think it does, though, it appears bugged; it doesn't seem to handle the case where b's value is greater than all values in the list.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top