Skip to content

nltd101/dijkstra-for-pointer-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Dijkstra For Pointer Graph

This soure code illustrates how to apply Dijkstra algorithm into Linked List.

Installation

It requires Visual Stuio to run. Initially, you need to open project with Visual Studio. After that, you could change input data by modifying file main.cpp. Finally, source code of function Dijkstra:

void Dijktra(Cnode* u,string LABEL,list<Cnode*>ListDistance) {
	u->DISTANCE = 0;
	Cnode* nodemin=NULL;
	while (true)
	{
		int minDistance=-1;
		for (list<Cnode*>::iterator it = ListDistance.begin();it != ListDistance.end();it++)
		{
			if ((!(*it)->CHECKED))
			{
				if ((minDistance == -1)||((*it)->DISTANCE<minDistance))
				{
					minDistance = (*it)->DISTANCE;
					nodemin = *it;
				}
			}
		}
		if ((nodemin->LABEL==LABEL)||(minDistance==-1))
		{
			break;
		}
		nodemin->CHECKED = true;
		;
		list<int>::iterator itdis = nodemin->LISTweight.begin();
		for (list<Cnode*>::iterator it = nodemin->LISTn.begin();
			 it!= nodemin->LISTn.end(), itdis!=nodemin->LISTweight.end(); it++,itdis++)
		{
			//if (!(*it)->CHECKED)
			{
				//(*it)->CHECKED = true;
				if ((nodemin->DISTANCE+*itdis<(*it)->DISTANCE))
				{
					(*it)->DISTANCE = nodemin->DISTANCE + *itdis;
					(*it)->TRACE = nodemin;
				}

			}
		}
	}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published