Изменения

Перейти к: навигация, поиск
Псевдокод
|
'''function''' <tex>\mathtt{findHamiltonianCycle}(G):</tex>
<tex>\mathtt{Queue}</tex> <tex>\mathtt{queue}</tex>
'''for''' <tex> v \in V</tex>: <font color = "green">// Добавляем все вершины графа в очередь</font>
<tex>\mathtt{queue.pushBack}(<tex>v)</tex>)
'''for''' k = 0...n*(n - 1)
'''if''' <tex>(\mathtt{queue.at}(0), \mathtt{queue.at}(1)) <tex> \notin E</tex> <font color = "green">// Проверяем существования ребра между первой и второй вершинами очереди</font> <tex>\mathtt{i} = 2</tex> '''while''' <tex>(\mathtt{queue.at}(0), \mathtt{queue.at}(i)) <tex> \notin E</tex> '''or''' <tex>(\mathtt{queue.at}(1), \mathtt{queue.at}(i + 1)) <tex> \notin E</tex> <tex>\mathtt{i}</tex>++ <font color = "green">// Ищем индекс удовлетворяющую условию вершины</font> <tex>\mathtt{queue.swapSubQueue}(2, i)</tex> <font color = "green">// Разворачиваем часть перестановки от 2-й до найденной позиции включительно</font> <tex>\mathtt{queue.pushBack}(\mathtt{queue.top}())</tex> <tex>\mathtt{queue.pop}()</tex>
|}
212
правок

Навигация