Изменения

Перейти к: навигация, поиск
м
rollbackEdits.php mass rollback
== Псевдокод ==
Функция <tex>\mathtt{findHamiltonianCycle}</tex> получает на вход граф <tex> G </tex > и находит гамильтонов цикл в нем.
* <tex> queue </tex> {{---}} очередь вершин графа <tex>G = \left \langle {V, E} \right \rangle</tex>
{| width = 100%
|-
|
'''function''' <tex>\mathtt{findHamiltonianCycle}(G):</tex> <tex>\mathttleft \langle {QueueV, E}</tex> <tex>\mathtt{queue}right \rangle</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}(21, i)</tex> <font color = "green">// Разворачиваем часть перестановки от 21-й до найденной позиции включительно</font> <tex>\mathtt{queue.pushBack}(\mathtt{queue.top}())</tex> <tex>\mathtt{queue.pop}()</tex>
|}
1632
правки

Навигация