Deitools
Deitools

Reputation: 431

How to order this list?

I have a list of applications. I need to order them in a specific way and install in that order.

Things to consider:

Some applications have as a requirement, another application.

Some applications need a reboot before install next application, we want this applications to stay at bottom of the list but some of them may require an application that doesn't need a reboot, so, it can happen that some application that doesn't have any requirement neither a reboot, goes after an application that needs a reboot.

An example:

P1 (Reboot)
P2 (Needs P3)
P3
P4 (Needs P1)
P5 (Reboot and needs P3)
P6 (Reboot)
P7

So, if we have the apps in that order:

P1 - P2 - P3 - P4 - P5 - P6 - P7

The correct order would be (for example):

P3 - P7 - P2 - P1 - P4 - P5 - P6

If theres a non reboot app that has as requirement an app that needs a reboot (like P4) would be better if they stay upper on list than the others reboot apps (P5 - P6)

Upvotes: 3

Views: 114

Answers (1)

Fred Foo
Fred Foo

Reputation: 363517

You need a topological sorting algorithm.

Upvotes: 3

Related Questions