mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-26 19:43:33 +08:00
style: format code
This commit is contained in:
@@ -8,9 +8,7 @@ int graph[V][V] = {
|
||||
{0, 5, 1, 2},
|
||||
{5, 0, 3, 3},
|
||||
{1, 3, 0, 4},
|
||||
{2, 3, 4, 0}
|
||||
};
|
||||
|
||||
{2, 3, 4, 0}};
|
||||
|
||||
struct mst
|
||||
{
|
||||
@@ -25,39 +23,39 @@ void initilize()
|
||||
{
|
||||
for (int i = 0; i < V; i++)
|
||||
{
|
||||
MST_Array[i].visited=false;
|
||||
MST_Array[i].key=INFINITY; // considering INFINITY as inifinity
|
||||
MST_Array[i].near=i;
|
||||
MST_Array[i].visited = false;
|
||||
MST_Array[i].key = INFINITY; // considering INFINITY as inifinity
|
||||
MST_Array[i].near = i;
|
||||
}
|
||||
|
||||
MST_Array[0].key=0;
|
||||
MST_Array[0].key = 0;
|
||||
}
|
||||
|
||||
void updateNear()
|
||||
{
|
||||
for (int v = 0; v < V; v++)
|
||||
{
|
||||
int min=INFINITY;
|
||||
int minIndex=0;
|
||||
int min = INFINITY;
|
||||
int minIndex = 0;
|
||||
for (int i = 0; i < V; i++)
|
||||
{
|
||||
if (MST_Array[i].key<min && MST_Array[i].visited==false && MST_Array[i].key!=INFINITY)
|
||||
if (MST_Array[i].key < min && MST_Array[i].visited == false && MST_Array[i].key != INFINITY)
|
||||
{
|
||||
min=MST_Array[i].key;
|
||||
minIndex=i;
|
||||
min = MST_Array[i].key;
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
MST_Array[minIndex].visited=true;
|
||||
|
||||
|
||||
MST_Array[minIndex].visited = true;
|
||||
|
||||
for (int i = 0; i < V; i++)
|
||||
{
|
||||
if (graph[minIndex][i]!=0 && graph[minIndex][i]<INFINITY)
|
||||
if (graph[minIndex][i] != 0 && graph[minIndex][i] < INFINITY)
|
||||
{
|
||||
if (graph[minIndex][i]<MST_Array[i].key)
|
||||
if (graph[minIndex][i] < MST_Array[i].key)
|
||||
{
|
||||
MST_Array[i].key=graph[minIndex][i];
|
||||
MST_Array[i].near=minIndex;
|
||||
MST_Array[i].key = graph[minIndex][i];
|
||||
MST_Array[i].near = minIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,11 +66,10 @@ void show()
|
||||
{
|
||||
for (int i = 0; i < V; i++)
|
||||
{
|
||||
cout<<i<<" - "<<MST_Array[i].near<<"\t"<<graph[i][MST_Array[i].near]<<"\n";
|
||||
cout << i << " - " << MST_Array[i].near << "\t" << graph[i][MST_Array[i].near] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
initilize();
|
||||
|
||||
Reference in New Issue
Block a user