1

This question is most easy to describe as a modification of that my question.

Suppose that question is solved as the following Python class:

class Traversal(object):
 # ...
 def next(self): # next node of the graph
 # ...

Now I want to modify the algorithm: Sometimes I want to traverse to the next non-preferred node.

class Traversal(object):
 # ...
 def next(self): # next node of the graph
 # ...
 def next2(self): # next non-preferred node of the graph
 # ...

How to modify the algorithm to implement next2()?

Note that both next() and next2() return a graph node and this node should be recorded not to be traversed again.

Sorry I cannot describe the real example where this problem appears, it would be too verbose. You can see https://en.wikiversity.org/wiki/Automatic_transformation_of_XML_namespaces for the big problem I am solving.

asked Apr 30, 2018 at 12:45
2
  • Regarding your question, I find it unclear. Regarding your goal of "transformation of XML namespaces", isn't that already doable with XSLT? Commented Apr 30, 2018 at 13:23
  • @dagnelies XSLT is one of many engines my transformations use Commented Apr 30, 2018 at 13:29

1 Answer 1

2

It seems I've found a good solution of my problem:

Because we have only two priorities: "preferred" and "non-preferred", the priority queue can be easily implemented as two queues: "preferred" and "non-preferred". In the usual (next()) traversal order, we will look first into preferred and then if it is empty non-preferred queue. If we need next2() traversal order, then instead look into non-preferred queue only.

answered Apr 30, 2018 at 14:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.