Preorder traversal through Adjacency List

I am trying to convert my EdgeList into a Adjacency List and then preorder traverse through it. I am pretty sure the conversion to Adjacency List is working correctly, but I am having troubles with preorder traversing through it. I have tried to do it with DFS, but it gives me the wrong result.

Here are my edges:

{index1=0, index2=2}

{index1=3, index2=4}

{index1=1, index2=4}

{index1=0, index2=5}

{index1=2, index2=6}

{index1=1, index2=5}

{index1=2, index2=7}

And this is what the linked list looks like.

0 - 2 - 5

1 - 4 - 5

2 - 6 - 7

3 - 4


linked[2, 5]

linked[4, 5]

linked[6, 7]


Now I...

Read More »

By: StackOverFlow - 7 days ago

Related Posts